Finding the number of UIDs on unix

Discussion in 'C++' started by frikk, Apr 12, 2007.

  1. frikk

    frikk Guest

    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
    frikk, Apr 12, 2007
    #1
    1. Advertising

  2. frikk

    red floyd Guest

    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-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.
    red floyd, Apr 12, 2007
    #2
    1. Advertising

  3. frikk

    Default User Guest

    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
    Default User, Apr 12, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    12
    Views:
    1,617
    Dave Thompson
    Jan 10, 2005
  2. Daniel T.

    How to find MAC address and uids?

    Daniel T., Nov 10, 2004, in forum: Python
    Replies:
    4
    Views:
    3,836
    Mike Hall
    Nov 10, 2004
  3. dawn

    Unix C programming for finding file

    dawn, Nov 24, 2004, in forum: C Programming
    Replies:
    46
    Views:
    1,051
    Dan Pop
    Dec 7, 2004
  4. Replies:
    18
    Views:
    608
    Dave Thompson
    Jan 10, 2005
  5. Robert Wallace

    my own perl "dos->unix"/"unix->dos"

    Robert Wallace, Jan 21, 2004, in forum: Perl Misc
    Replies:
    7
    Views:
    267
    Michele Dondi
    Jan 22, 2004
Loading...

Share This Page