Finding the number of UIDs on unix

F

frikk

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
 
R

red floyd

frikk said:
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-lite/how-to-post.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.
 
D

Default User

frikk said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,444
Messages
2,571,709
Members
48,796
Latest member
Greg L.
Top