Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

users and there processes

  • 10-09-2007 3:54pm
    #1
    Closed Accounts Posts: 91 ✭✭


    I am trying to write a script to list all users and their processes. I cant seem to find out how to link the PID to the user. For example if i run ps -a I get a nice list of all the processes running and their PID, but no information about which user is running them. I need the users real name not login in name so Joe Bloggs instead of joe.bloggs

    The output should look similar to this.


    Joe Bloggs
    PID TTY TIME CMD
    31799 pts/3 00:00:00 vim
    31866 pts/3 00:00:00 vim
    2495 pts/7 00:00:00 vim
    8368 pts/0 00:00:00 vim
    9544 pts/2 00:00:00 ps

    Henry Hill
    PID TTY TIME CMD
    8368 pts/0 00:00:00 vim
    9544 pts/2 00:00:00 ps

    anyone any ideas


Comments

  • Technology & Internet Moderators Posts: 28,830 Mod ✭✭✭✭oscarBravo


    Have you tried "man ps"?


  • Closed Accounts Posts: 91 ✭✭magnia


    yes, u any ideas. ive tried all the options that the man ps showed me. but i still dont know how i am going to get the username to appear like Joe Bloggs instead joe.bloggs


  • Technology & Internet Moderators Posts: 28,830 Mod ✭✭✭✭oscarBravo


    Users' real names are in /etc/passwd.


  • Closed Accounts Posts: 91 ✭✭magnia


    hmmm so could i do something like ps -aux|grep /etc/passwd


  • Registered Users, Registered Users 2 Posts: 1,193 ✭✭✭liamo


    Off the top of my head :
    1. cat the contents of /etc/passwd through awk to retrieve the username and comment (usually containing the real name) fields.
    2. iterate through the result of 1
    3. for each iteration of 2, count the processes for each user by piping a filtered list of processes (ps -u) into wc -l
    4. if the result of 3 is > 1 then output the real name and the result of ps -u <username>

    Probably about 10 lines of script to accomplish the above.
    The actual scripting I leave to you ;)

    Regards,

    Liam


  • Advertisement
  • Closed Accounts Posts: 181 ✭✭deadfingers


    Try prstat


  • Closed Accounts Posts: 91 ✭✭magnia


    yup catted the file then piped it and mess around another bit and finally got what i was looking for wooh


Advertisement