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

How to monitor thread/CPU/memory usage of a particular process

Options
  • 05-06-2008 11:20am
    #1
    Registered Users Posts: 5,580 ✭✭✭


    Can anyone help with this?

    Im looking to take a simple snapshot of a particular process. I know of top, prstat, ps -ef ETC ETC but they all give long lists. Just want a simple script/command to look at one process

    Also, i only know the process by name, not PID so will probably need some funky code to get the PID i guess...

    Thanks for any help! :pac:


Comments

  • Moderators, Science, Health & Environment Moderators Posts: 10,079 Mod ✭✭✭✭marco_polo


    Can anyone help with this?

    Im looking to take a simple snapshot of a particular process. I know of top, prstat, ps -ef ETC ETC but they all give long lists. Just want a simple script/command to look at one process

    Also, i only know the process by name, not PID so will probably need some funky code to get the PID i guess...

    Thanks for any help! :pac:

    Something like ps -ef | grep [process name] will return just the line you are intersted in and you could then extract the PID from that (Please don't ask me how :p).


  • Closed Accounts Posts: 2,267 ✭✭✭h57xiucj2z946q


    Can anyone help with this?

    Im looking to take a simple snapshot of a particular process. I know of top, prstat, ps -ef ETC ETC but they all give long lists. Just want a simple script/command to look at one process

    Also, i only know the process by name, not PID so will probably need some funky code to get the PID i guess...

    Thanks for any help! :pac:


    you can use pgrep to get pid of a process by name. this can return more than 1 result by the way.

    prstat can be used with -p option for listing of single process.


  • Closed Accounts Posts: 2,267 ✭✭✭h57xiucj2z946q


    if you have a unique process, that is, only 1 instance of it executed on the system, then you could use:

    prstat -p `pgrep xclock`

    there backticks, not quotes (above the tab key)


  • Registered Users Posts: 2,082 ✭✭✭Tobias Greeshman


    marco_polo wrote: »
    Something like ps -ef | grep [process name] will return just the line you are intersted in and you could then extract the PID from that (Please don't ask me how :p).

    Something like this should work, I haven't tried this out:
    ps -ef | grep <process | grep -v grep | cut -f 3 -d ' '

    Change the -f number until you get the right number


  • Registered Users Posts: 5,580 ✭✭✭veryangryman


    Thats cool but how would you specifically get the CPU for instance?

    Those ps -ef command only gives the PID


  • Advertisement
  • Registered Users Posts: 545 ✭✭✭ravydavygravy


    I think this is what you are looking for:
    ps -eo comm,uid,pid,%cpu,%mem | grep <name-of-process>
    

    Have a look at the man page for ps, to see what other information you can print out.

    ~Dave


Advertisement