Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

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

  • 05-06-2008 11:20AM
    #1
    Registered Users, Registered Users 2 Posts: 5,753 ✭✭✭


    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,093 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, Registered Users 2 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, Registered Users 2 Posts: 5,753 ✭✭✭veryangryman


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

    Those ps -ef command only gives the PID


  • Advertisement
  • Registered Users, Registered Users 2 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