473,480 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Finding the number of UIDs on unix

Hey everyone,
(Sorry about the first message if it made it - i got cut off
early). I have a homework problem for my Operating Systems class. I
am supposed to use a command such as "ps -aux" and return "N number of
users, M number of processes". How am I to go about doing this? I am
not very familiar with string parsing in c++, is this the only way? I
am talking about getting the output from "ps -aux" and parsing it to
retrieve the number of unique UIDs.

Any suggestions would be appreciated. Thank you in advance!

Blaine
University of Cincinnati

Apr 12 '07 #1
2 1579
frikk wrote:
Hey everyone,
(Sorry about the first message if it made it - i got cut off
early). I have a homework problem for my Operating Systems class. I
am supposed to use a command such as "ps -aux" and return "N number of
users, M number of processes". How am I to go about doing this? I am
not very familiar with string parsing in c++, is this the only way? I
am talking about getting the output from "ps -aux" and parsing it to
retrieve the number of unique UIDs.
Please see the FAQ, in particular 5.2 and 5.3.

http://www.parashift.com/c++-faq-lit...t.html#faq-5.2

However, I'm feeling nice.

1. RTFM to find out the format from ps -aux
2. Read into a vector of strings
3. Parse the strings into subfields (note: stringstreams may be useful
here).
4. Process the data, using the knowledge gained in step 1.
Apr 12 '07 #2
frikk wrote:
Hey everyone,
(Sorry about the first message if it made it - i got cut off
early). I have a homework problem for my Operating Systems class. I
am supposed to use a command such as "ps -aux" and return "N number of
users, M number of processes". How am I to go about doing this? I am
not very familiar with string parsing in c++, is this the only way? I
am talking about getting the output from "ps -aux" and parsing it to
retrieve the number of unique UIDs.
Sounds like you're working on a UNIX system. As such, the newsgroup
comp.unix.programmer is likely the best one for your question.

Some hints along the way, ps is a user command. You'll need to find a
way to capture the output that would normally be displayed by the
shell. Perhaps something like popen() will right for you. They can help
you with that there.

I've gone ahead and crossposted this to comp.unix.programmer and set
followups.

Once you solve the problem of reading the output, you may have some
programming questions that would be appropriate for this newsgroup.


Brian
Apr 12 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
12350
by: Hal Vaughan | last post by:
I want to have a config file for my program, which means I need to know where the config file is. If I type: java myclass and it runs myclass.class, is there any way to obtain the location of...
46
2469
by: dawn | last post by:
Hi all, I am now working on a C program under Unix. The requirement for the program is that: A file name is passed to program as a parameter. The program will Find files under a specified...
9
10260
by: minil | last post by:
Hi any c function in linux to return size of directory (Including its files & subdirectories & its files).. I can stat() only files . not for directories. please reply me soon Thanks in...
1
2942
by: wobbles | last post by:
Hi Everyone, I have a server which reads information from a "server.exe.config" file and a client that also reads from its "client.exe.config" file. If the server location or the port number...
20
10805
by: Joel Hedlund | last post by:
Hi all! I use python for writing terminal applications and I have been bothered by how hard it seems to be to determine the terminal size. What is the best way of doing this? At the end I've...
13
1984
by: athiane | last post by:
I want a way to parse out all function names that appear in a couple of C files. When the parsing logic finds a function name in a file, it should print out the Function name, line number and file...
12
2392
by: Sankar | last post by:
Dear all, I am programming in Linux , wherein I need to know a couple of things. 1) Does an API exist that can copy file onto another file ( an API equivalent of 'cp') ? 2) Is there an API...
21
2980
by: Tom Gur | last post by:
Hi, It's seems that csh and tcsh acts a bit different when handling special characters in quotes. i.e: if i'll supply my program with the following arguments: -winpath "c:\\temp\\" tcsh will...
11
4893
by: John | last post by:
Is there a way to find the number of processors on a machine (on linux/ windows/macos/cygwin) using python code (using the same code/cross platform code)?
0
7041
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7043
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6737
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6921
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5336
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4481
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2984
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.