How to monitor CPU/memory usage of a single process?












142















I would like to monitor one process's memory / cpu usage in real time. Similar to top but targeted at only one process, preferably with a history graph of some sort.










share|improve this question

























  • What memory statistics do you want? There are lots of them.

    – vwduder
    Jan 13 '11 at 11:33











  • Memory usage over a given time frame, current usage, maximum usage, average.

    – Josh K
    Jan 13 '11 at 11:33
















142















I would like to monitor one process's memory / cpu usage in real time. Similar to top but targeted at only one process, preferably with a history graph of some sort.










share|improve this question

























  • What memory statistics do you want? There are lots of them.

    – vwduder
    Jan 13 '11 at 11:33











  • Memory usage over a given time frame, current usage, maximum usage, average.

    – Josh K
    Jan 13 '11 at 11:33














142












142








142


39






I would like to monitor one process's memory / cpu usage in real time. Similar to top but targeted at only one process, preferably with a history graph of some sort.










share|improve this question
















I would like to monitor one process's memory / cpu usage in real time. Similar to top but targeted at only one process, preferably with a history graph of some sort.







shell process monitoring top






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 4 '11 at 17:06









Tshepang

26.3k72186264




26.3k72186264










asked Aug 17 '10 at 3:21









Josh KJosh K

1,09131314




1,09131314













  • What memory statistics do you want? There are lots of them.

    – vwduder
    Jan 13 '11 at 11:33











  • Memory usage over a given time frame, current usage, maximum usage, average.

    – Josh K
    Jan 13 '11 at 11:33



















  • What memory statistics do you want? There are lots of them.

    – vwduder
    Jan 13 '11 at 11:33











  • Memory usage over a given time frame, current usage, maximum usage, average.

    – Josh K
    Jan 13 '11 at 11:33

















What memory statistics do you want? There are lots of them.

– vwduder
Jan 13 '11 at 11:33





What memory statistics do you want? There are lots of them.

– vwduder
Jan 13 '11 at 11:33













Memory usage over a given time frame, current usage, maximum usage, average.

– Josh K
Jan 13 '11 at 11:33





Memory usage over a given time frame, current usage, maximum usage, average.

– Josh K
Jan 13 '11 at 11:33










8 Answers
8






active

oldest

votes


















121














On Linux, top actually supports focusing on a single process, although it naturally doesn't have a history graph:



top -p PID


This is also available on Mac OS X with a different syntax:



top -pid PID





share|improve this answer





















  • 9





    And since you may not want to look up the PID every time, try something like top -p `pgrep -f /usr/bin/kvm`.

    – Stefan Lasiewski
    Aug 17 '10 at 3:33













  • I use Cacti to monitor some individual processes, but installing a full blown Cacti installation sounds too complex for the simple situation asked here.

    – Stefan Lasiewski
    Aug 17 '10 at 3:34











  • @Stefan: I'm assuming I would have to run that remotely?

    – Josh K
    Aug 17 '10 at 4:00











  • @Josh : Yes you would need to run Cacti (Which requires MySQL, Apache and few other packages) on another server. On most distros, it's pretty simple to install using Yum or apt-get.

    – Stefan Lasiewski
    Aug 17 '10 at 20:48











  • @Stefan if you want to to check remotly you can do ssh@remotehost 'top -p PID > ~hostname_pid.txt; exit'and

    – klerk
    May 13 '14 at 20:02



















56














htop is a great replacement to top. It has... Colors! Simple keyboard shortcuts! Scroll the list using the arrow keys! Kill a process without leaving and without taking note of the PID! Mark multiple processes and kill them all!



Among all of the features, the manpage says you can press F to follow a process.



Really, you should try htop. I never started top again, after the first time I used htop.



Display a single process:



htop -p PID






share|improve this answer





















  • 7





    +1 for htop. This is one of the first program I install on a new system. It makes my life much easier. The tree view is also very handy.

    – Barthelemy
    Nov 24 '10 at 12:22






  • 7





    top also has colors. Press z.

    – Tshepang
    Jan 12 '11 at 1:41






  • 2





    You're right! top has colors! Too bad its colors are quite useless, specially when compared to htop (which fades other users processes and highlights the program basename).

    – Denilson Sá Maia
    Jan 12 '11 at 18:17






  • 1





    And htop -p PID will work too, just like the example given by @Michael Mrozek.

    – noisebleed
    Nov 25 '14 at 12:05






  • 1





    Then only reason to use top, is because htop is not available or can't be installed. That is why htop was created, to provide much more features.

    – lepe
    Apr 13 '15 at 2:55



















40














psrecord



The following addresses history graph of some sort. Python psrecord package does exactly this.



pip install psrecord                             # local user install
sudo apt-get install python-matplotlib python-tk # for plotting; or via pip


For single process it's the following (stopped by Ctrl+C):



psrecord $(pgrep proc-name1) --interval 1 --plot plot1.png


For several processes the following script is helpful to synchronise the charts:



#!/bin/bash    
psrecord $(pgrep proc-name1) --interval 1 --duration 60 --plot plot1.png &
P1=$!
psrecord $(pgrep proc-name2) --interval 1 --duration 60 --plot plot2.png &
P2=$!
wait $P1 $P2
echo 'Done'


Charts look like:
psrecord example



memory_profiler



The package provides RSS-only sampling (plus some Python-specific options). It can also record process with its children processes (see mprof --help).



pip install memory_profiler
mprof run /path/to/executable
mprof plot


By default this pops up a Tkinter-based (python-tk may be needed) chart explorer which can be exported:



mprof



graphite-stack & statsd



It may seem an overkill for a simple one-off test, but for something like a several-day debugging it's, for sure, reasonable. A handy all-in-one raintank/graphite-stack (from Grafana's authors) image and psutil and statsd client. procmon.py provides an implementation.



$ docker run --rm -p 8080:3000 -p 8125:8125/udp raintank/graphite-stack


Then in another terminal, after starting target process:



$ sudo apt-get install python-statsd python-psutil # or via pip
$ python procmon.py -s localhost -f chromium -r 'chromium.*'


Then opening Grafana at http://localhost:8080, authentication as admin:admin, setting up datasource https://localhost, you can plot a chart like:



grafana chart



graphite-stack & telegraf



Instead of Python script sending the metrics to Statsd, telegraf (and procstat input plugin) can be used to send the metrics to Graphite directly.



Minimal telegraf configuration looks like:



[agent]
interval = "1s"

[[outputs.graphite]]
servers = ["localhost:2003"]
prefix = "testprfx"

[[inputs.procstat]]
pid_file = "/path/to/file/with.pid"


Then run line telegraf --config minconf.conf. Grafana part is the same, except metrics names.



sysdig



sysdig (available in Debian and Ubuntu's repos) with sysdig-inspect UI look very promising, providing extremely fine-grained details along with CPU utilisation and RSS, but unfortunately the UI is unable to render them, and sysdig can't filter procinfo event by process at the time of writing. Though, this should be possible with a custom chisel (an sysdig extension written in Lua).






share|improve this answer


























  • pgrep systemd is giving multiple lines of output, and thus bugs the psrecord, what should be done? I just want to test with any process.

    – EralpB
    Apr 11 '18 at 7:09






  • 1





    @EralpB pgrep --help to the rescue. There's at least --newest and --oldest.

    – saaj
    Apr 11 '18 at 9:03











  • This should be the accepted answer, since it actually gives a memory usage history plot. Note for the psrecord method, Ctrl+C on the psrecord process just quits without saving a plot, you need to end the process-under-test.

    – user2561747
    Jan 26 at 3:03



















8














To use that information on a script you can do this:



calcPercCpu.sh



#!/bin/bash
nPid=$1;
nTimes=10; # customize it
delay=0.1; # customize it
strCalc=`top -d $delay -b -n $nTimes -p $nPid
|grep $nPid
|sed -r -e "s;ss*; ;g" -e "s;^ *;;"
|cut -d' ' -f9
|tr 'n' '+'
|sed -r -e "s;(.*)[+]$;1;" -e "s/.*/scale=2;(&)/$nTimes/"`;
nPercCpu=`echo "$strCalc" |bc -l`
echo $nPercCpu


use like: calcPercCpu.sh 1234 where 1234 is the pid



For the specified $nPid, it will measure the average of 10 snapshots of the cpu usage in a whole of 1 second (delay of 0.1s each * nTimes=10); that provides a good and fast accurate result of what is happening in the very moment.



Tweak the variables to your needs.






share|improve this answer


























  • Uhm, 10 processes to monitor the cpu usage of 1?

    – xebeche
    Mar 13 at 14:19











  • @xebeche "it will measure the average of 10 snapshots" "nTimes=10; # customize it" :)

    – Aquarius Power
    3 hours ago













  • I meant I don't like the fact that you call 10 processes to retrieve 1 number ($nPercCpu): shell, top, grep, sed, cut ... bc. Many if not all of these you could for instance merge into 1 Sed or Awk script.

    – xebeche
    2 hours ago



















6














I normally use following two :




  1. HP caliper : its very good tool for monitoring processes it you can check call graph and other low level information also. But please note its free only for personal use.


  2. daemontools : a collection of tools for managing UNIX services







share|improve this answer





















  • 5





    I used daemontools for years. It's great as a supervisor/watchdog for other processes. How does it help you monitor CPU/memory usage for one process?

    – Stefan Lasiewski
    Aug 19 '10 at 4:05



















2














If you know process name you can use



top -p $(pidof <process_name>)





share|improve this answer



















  • 7





    That's pretty much what the accepted answer, from years ago, and its first comment say.

    – dhag
    Apr 29 '15 at 15:26



















1














If you have a cut-down Linux distribution where top does not have per process (-p) option or related options, you can parse the output of the top command for your process name to get the CPU usage information per process.



while true;  do top -bn1 | awk '/your_process_name/ {print  $8}' ; sleep 1; done


8 represents the CPU usage per process in the output of the top command in my embedded Linux distribution






share|improve this answer

































    0














    If you need the averages for a period of time of a specific process, try the accumulative -c option of top:



    top -c a -pid PID


    "-c a" found in top for Mac 10.8.5.



    For Scientific Linux, the option is -S, that can be set interactively.






    share|improve this answer


























    • You'll likely want to add further details around which version(s) of top actually provide this feature. My version on Fedora 19 does not. Same too on Ubuntu 13.04.

      – slm
      May 12 '14 at 1:22











    • You're right!, I was so happy of having found something useful, I forgot I was in my mac at home.

      – Kieleth
      May 13 '14 at 19:34











    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "106"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f554%2fhow-to-monitor-cpu-memory-usage-of-a-single-process%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    8 Answers
    8






    active

    oldest

    votes








    8 Answers
    8






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    121














    On Linux, top actually supports focusing on a single process, although it naturally doesn't have a history graph:



    top -p PID


    This is also available on Mac OS X with a different syntax:



    top -pid PID





    share|improve this answer





















    • 9





      And since you may not want to look up the PID every time, try something like top -p `pgrep -f /usr/bin/kvm`.

      – Stefan Lasiewski
      Aug 17 '10 at 3:33













    • I use Cacti to monitor some individual processes, but installing a full blown Cacti installation sounds too complex for the simple situation asked here.

      – Stefan Lasiewski
      Aug 17 '10 at 3:34











    • @Stefan: I'm assuming I would have to run that remotely?

      – Josh K
      Aug 17 '10 at 4:00











    • @Josh : Yes you would need to run Cacti (Which requires MySQL, Apache and few other packages) on another server. On most distros, it's pretty simple to install using Yum or apt-get.

      – Stefan Lasiewski
      Aug 17 '10 at 20:48











    • @Stefan if you want to to check remotly you can do ssh@remotehost 'top -p PID > ~hostname_pid.txt; exit'and

      – klerk
      May 13 '14 at 20:02
















    121














    On Linux, top actually supports focusing on a single process, although it naturally doesn't have a history graph:



    top -p PID


    This is also available on Mac OS X with a different syntax:



    top -pid PID





    share|improve this answer





















    • 9





      And since you may not want to look up the PID every time, try something like top -p `pgrep -f /usr/bin/kvm`.

      – Stefan Lasiewski
      Aug 17 '10 at 3:33













    • I use Cacti to monitor some individual processes, but installing a full blown Cacti installation sounds too complex for the simple situation asked here.

      – Stefan Lasiewski
      Aug 17 '10 at 3:34











    • @Stefan: I'm assuming I would have to run that remotely?

      – Josh K
      Aug 17 '10 at 4:00











    • @Josh : Yes you would need to run Cacti (Which requires MySQL, Apache and few other packages) on another server. On most distros, it's pretty simple to install using Yum or apt-get.

      – Stefan Lasiewski
      Aug 17 '10 at 20:48











    • @Stefan if you want to to check remotly you can do ssh@remotehost 'top -p PID > ~hostname_pid.txt; exit'and

      – klerk
      May 13 '14 at 20:02














    121












    121








    121







    On Linux, top actually supports focusing on a single process, although it naturally doesn't have a history graph:



    top -p PID


    This is also available on Mac OS X with a different syntax:



    top -pid PID





    share|improve this answer















    On Linux, top actually supports focusing on a single process, although it naturally doesn't have a history graph:



    top -p PID


    This is also available on Mac OS X with a different syntax:



    top -pid PID






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Apr 10 '14 at 21:23









    Gilles

    543k12811001617




    543k12811001617










    answered Aug 17 '10 at 3:27









    Michael MrozekMichael Mrozek

    61.9k29193213




    61.9k29193213








    • 9





      And since you may not want to look up the PID every time, try something like top -p `pgrep -f /usr/bin/kvm`.

      – Stefan Lasiewski
      Aug 17 '10 at 3:33













    • I use Cacti to monitor some individual processes, but installing a full blown Cacti installation sounds too complex for the simple situation asked here.

      – Stefan Lasiewski
      Aug 17 '10 at 3:34











    • @Stefan: I'm assuming I would have to run that remotely?

      – Josh K
      Aug 17 '10 at 4:00











    • @Josh : Yes you would need to run Cacti (Which requires MySQL, Apache and few other packages) on another server. On most distros, it's pretty simple to install using Yum or apt-get.

      – Stefan Lasiewski
      Aug 17 '10 at 20:48











    • @Stefan if you want to to check remotly you can do ssh@remotehost 'top -p PID > ~hostname_pid.txt; exit'and

      – klerk
      May 13 '14 at 20:02














    • 9





      And since you may not want to look up the PID every time, try something like top -p `pgrep -f /usr/bin/kvm`.

      – Stefan Lasiewski
      Aug 17 '10 at 3:33













    • I use Cacti to monitor some individual processes, but installing a full blown Cacti installation sounds too complex for the simple situation asked here.

      – Stefan Lasiewski
      Aug 17 '10 at 3:34











    • @Stefan: I'm assuming I would have to run that remotely?

      – Josh K
      Aug 17 '10 at 4:00











    • @Josh : Yes you would need to run Cacti (Which requires MySQL, Apache and few other packages) on another server. On most distros, it's pretty simple to install using Yum or apt-get.

      – Stefan Lasiewski
      Aug 17 '10 at 20:48











    • @Stefan if you want to to check remotly you can do ssh@remotehost 'top -p PID > ~hostname_pid.txt; exit'and

      – klerk
      May 13 '14 at 20:02








    9




    9





    And since you may not want to look up the PID every time, try something like top -p `pgrep -f /usr/bin/kvm`.

    – Stefan Lasiewski
    Aug 17 '10 at 3:33







    And since you may not want to look up the PID every time, try something like top -p `pgrep -f /usr/bin/kvm`.

    – Stefan Lasiewski
    Aug 17 '10 at 3:33















    I use Cacti to monitor some individual processes, but installing a full blown Cacti installation sounds too complex for the simple situation asked here.

    – Stefan Lasiewski
    Aug 17 '10 at 3:34





    I use Cacti to monitor some individual processes, but installing a full blown Cacti installation sounds too complex for the simple situation asked here.

    – Stefan Lasiewski
    Aug 17 '10 at 3:34













    @Stefan: I'm assuming I would have to run that remotely?

    – Josh K
    Aug 17 '10 at 4:00





    @Stefan: I'm assuming I would have to run that remotely?

    – Josh K
    Aug 17 '10 at 4:00













    @Josh : Yes you would need to run Cacti (Which requires MySQL, Apache and few other packages) on another server. On most distros, it's pretty simple to install using Yum or apt-get.

    – Stefan Lasiewski
    Aug 17 '10 at 20:48





    @Josh : Yes you would need to run Cacti (Which requires MySQL, Apache and few other packages) on another server. On most distros, it's pretty simple to install using Yum or apt-get.

    – Stefan Lasiewski
    Aug 17 '10 at 20:48













    @Stefan if you want to to check remotly you can do ssh@remotehost 'top -p PID > ~hostname_pid.txt; exit'and

    – klerk
    May 13 '14 at 20:02





    @Stefan if you want to to check remotly you can do ssh@remotehost 'top -p PID > ~hostname_pid.txt; exit'and

    – klerk
    May 13 '14 at 20:02













    56














    htop is a great replacement to top. It has... Colors! Simple keyboard shortcuts! Scroll the list using the arrow keys! Kill a process without leaving and without taking note of the PID! Mark multiple processes and kill them all!



    Among all of the features, the manpage says you can press F to follow a process.



    Really, you should try htop. I never started top again, after the first time I used htop.



    Display a single process:



    htop -p PID






    share|improve this answer





















    • 7





      +1 for htop. This is one of the first program I install on a new system. It makes my life much easier. The tree view is also very handy.

      – Barthelemy
      Nov 24 '10 at 12:22






    • 7





      top also has colors. Press z.

      – Tshepang
      Jan 12 '11 at 1:41






    • 2





      You're right! top has colors! Too bad its colors are quite useless, specially when compared to htop (which fades other users processes and highlights the program basename).

      – Denilson Sá Maia
      Jan 12 '11 at 18:17






    • 1





      And htop -p PID will work too, just like the example given by @Michael Mrozek.

      – noisebleed
      Nov 25 '14 at 12:05






    • 1





      Then only reason to use top, is because htop is not available or can't be installed. That is why htop was created, to provide much more features.

      – lepe
      Apr 13 '15 at 2:55
















    56














    htop is a great replacement to top. It has... Colors! Simple keyboard shortcuts! Scroll the list using the arrow keys! Kill a process without leaving and without taking note of the PID! Mark multiple processes and kill them all!



    Among all of the features, the manpage says you can press F to follow a process.



    Really, you should try htop. I never started top again, after the first time I used htop.



    Display a single process:



    htop -p PID






    share|improve this answer





















    • 7





      +1 for htop. This is one of the first program I install on a new system. It makes my life much easier. The tree view is also very handy.

      – Barthelemy
      Nov 24 '10 at 12:22






    • 7





      top also has colors. Press z.

      – Tshepang
      Jan 12 '11 at 1:41






    • 2





      You're right! top has colors! Too bad its colors are quite useless, specially when compared to htop (which fades other users processes and highlights the program basename).

      – Denilson Sá Maia
      Jan 12 '11 at 18:17






    • 1





      And htop -p PID will work too, just like the example given by @Michael Mrozek.

      – noisebleed
      Nov 25 '14 at 12:05






    • 1





      Then only reason to use top, is because htop is not available or can't be installed. That is why htop was created, to provide much more features.

      – lepe
      Apr 13 '15 at 2:55














    56












    56








    56







    htop is a great replacement to top. It has... Colors! Simple keyboard shortcuts! Scroll the list using the arrow keys! Kill a process without leaving and without taking note of the PID! Mark multiple processes and kill them all!



    Among all of the features, the manpage says you can press F to follow a process.



    Really, you should try htop. I never started top again, after the first time I used htop.



    Display a single process:



    htop -p PID






    share|improve this answer















    htop is a great replacement to top. It has... Colors! Simple keyboard shortcuts! Scroll the list using the arrow keys! Kill a process without leaving and without taking note of the PID! Mark multiple processes and kill them all!



    Among all of the features, the manpage says you can press F to follow a process.



    Really, you should try htop. I never started top again, after the first time I used htop.



    Display a single process:



    htop -p PID







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Apr 13 '15 at 4:49









    lepe

    29727




    29727










    answered Aug 17 '10 at 22:47









    Denilson Sá MaiaDenilson Sá Maia

    9841814




    9841814








    • 7





      +1 for htop. This is one of the first program I install on a new system. It makes my life much easier. The tree view is also very handy.

      – Barthelemy
      Nov 24 '10 at 12:22






    • 7





      top also has colors. Press z.

      – Tshepang
      Jan 12 '11 at 1:41






    • 2





      You're right! top has colors! Too bad its colors are quite useless, specially when compared to htop (which fades other users processes and highlights the program basename).

      – Denilson Sá Maia
      Jan 12 '11 at 18:17






    • 1





      And htop -p PID will work too, just like the example given by @Michael Mrozek.

      – noisebleed
      Nov 25 '14 at 12:05






    • 1





      Then only reason to use top, is because htop is not available or can't be installed. That is why htop was created, to provide much more features.

      – lepe
      Apr 13 '15 at 2:55














    • 7





      +1 for htop. This is one of the first program I install on a new system. It makes my life much easier. The tree view is also very handy.

      – Barthelemy
      Nov 24 '10 at 12:22






    • 7





      top also has colors. Press z.

      – Tshepang
      Jan 12 '11 at 1:41






    • 2





      You're right! top has colors! Too bad its colors are quite useless, specially when compared to htop (which fades other users processes and highlights the program basename).

      – Denilson Sá Maia
      Jan 12 '11 at 18:17






    • 1





      And htop -p PID will work too, just like the example given by @Michael Mrozek.

      – noisebleed
      Nov 25 '14 at 12:05






    • 1





      Then only reason to use top, is because htop is not available or can't be installed. That is why htop was created, to provide much more features.

      – lepe
      Apr 13 '15 at 2:55








    7




    7





    +1 for htop. This is one of the first program I install on a new system. It makes my life much easier. The tree view is also very handy.

    – Barthelemy
    Nov 24 '10 at 12:22





    +1 for htop. This is one of the first program I install on a new system. It makes my life much easier. The tree view is also very handy.

    – Barthelemy
    Nov 24 '10 at 12:22




    7




    7





    top also has colors. Press z.

    – Tshepang
    Jan 12 '11 at 1:41





    top also has colors. Press z.

    – Tshepang
    Jan 12 '11 at 1:41




    2




    2





    You're right! top has colors! Too bad its colors are quite useless, specially when compared to htop (which fades other users processes and highlights the program basename).

    – Denilson Sá Maia
    Jan 12 '11 at 18:17





    You're right! top has colors! Too bad its colors are quite useless, specially when compared to htop (which fades other users processes and highlights the program basename).

    – Denilson Sá Maia
    Jan 12 '11 at 18:17




    1




    1





    And htop -p PID will work too, just like the example given by @Michael Mrozek.

    – noisebleed
    Nov 25 '14 at 12:05





    And htop -p PID will work too, just like the example given by @Michael Mrozek.

    – noisebleed
    Nov 25 '14 at 12:05




    1




    1





    Then only reason to use top, is because htop is not available or can't be installed. That is why htop was created, to provide much more features.

    – lepe
    Apr 13 '15 at 2:55





    Then only reason to use top, is because htop is not available or can't be installed. That is why htop was created, to provide much more features.

    – lepe
    Apr 13 '15 at 2:55











    40














    psrecord



    The following addresses history graph of some sort. Python psrecord package does exactly this.



    pip install psrecord                             # local user install
    sudo apt-get install python-matplotlib python-tk # for plotting; or via pip


    For single process it's the following (stopped by Ctrl+C):



    psrecord $(pgrep proc-name1) --interval 1 --plot plot1.png


    For several processes the following script is helpful to synchronise the charts:



    #!/bin/bash    
    psrecord $(pgrep proc-name1) --interval 1 --duration 60 --plot plot1.png &
    P1=$!
    psrecord $(pgrep proc-name2) --interval 1 --duration 60 --plot plot2.png &
    P2=$!
    wait $P1 $P2
    echo 'Done'


    Charts look like:
    psrecord example



    memory_profiler



    The package provides RSS-only sampling (plus some Python-specific options). It can also record process with its children processes (see mprof --help).



    pip install memory_profiler
    mprof run /path/to/executable
    mprof plot


    By default this pops up a Tkinter-based (python-tk may be needed) chart explorer which can be exported:



    mprof



    graphite-stack & statsd



    It may seem an overkill for a simple one-off test, but for something like a several-day debugging it's, for sure, reasonable. A handy all-in-one raintank/graphite-stack (from Grafana's authors) image and psutil and statsd client. procmon.py provides an implementation.



    $ docker run --rm -p 8080:3000 -p 8125:8125/udp raintank/graphite-stack


    Then in another terminal, after starting target process:



    $ sudo apt-get install python-statsd python-psutil # or via pip
    $ python procmon.py -s localhost -f chromium -r 'chromium.*'


    Then opening Grafana at http://localhost:8080, authentication as admin:admin, setting up datasource https://localhost, you can plot a chart like:



    grafana chart



    graphite-stack & telegraf



    Instead of Python script sending the metrics to Statsd, telegraf (and procstat input plugin) can be used to send the metrics to Graphite directly.



    Minimal telegraf configuration looks like:



    [agent]
    interval = "1s"

    [[outputs.graphite]]
    servers = ["localhost:2003"]
    prefix = "testprfx"

    [[inputs.procstat]]
    pid_file = "/path/to/file/with.pid"


    Then run line telegraf --config minconf.conf. Grafana part is the same, except metrics names.



    sysdig



    sysdig (available in Debian and Ubuntu's repos) with sysdig-inspect UI look very promising, providing extremely fine-grained details along with CPU utilisation and RSS, but unfortunately the UI is unable to render them, and sysdig can't filter procinfo event by process at the time of writing. Though, this should be possible with a custom chisel (an sysdig extension written in Lua).






    share|improve this answer


























    • pgrep systemd is giving multiple lines of output, and thus bugs the psrecord, what should be done? I just want to test with any process.

      – EralpB
      Apr 11 '18 at 7:09






    • 1





      @EralpB pgrep --help to the rescue. There's at least --newest and --oldest.

      – saaj
      Apr 11 '18 at 9:03











    • This should be the accepted answer, since it actually gives a memory usage history plot. Note for the psrecord method, Ctrl+C on the psrecord process just quits without saving a plot, you need to end the process-under-test.

      – user2561747
      Jan 26 at 3:03
















    40














    psrecord



    The following addresses history graph of some sort. Python psrecord package does exactly this.



    pip install psrecord                             # local user install
    sudo apt-get install python-matplotlib python-tk # for plotting; or via pip


    For single process it's the following (stopped by Ctrl+C):



    psrecord $(pgrep proc-name1) --interval 1 --plot plot1.png


    For several processes the following script is helpful to synchronise the charts:



    #!/bin/bash    
    psrecord $(pgrep proc-name1) --interval 1 --duration 60 --plot plot1.png &
    P1=$!
    psrecord $(pgrep proc-name2) --interval 1 --duration 60 --plot plot2.png &
    P2=$!
    wait $P1 $P2
    echo 'Done'


    Charts look like:
    psrecord example



    memory_profiler



    The package provides RSS-only sampling (plus some Python-specific options). It can also record process with its children processes (see mprof --help).



    pip install memory_profiler
    mprof run /path/to/executable
    mprof plot


    By default this pops up a Tkinter-based (python-tk may be needed) chart explorer which can be exported:



    mprof



    graphite-stack & statsd



    It may seem an overkill for a simple one-off test, but for something like a several-day debugging it's, for sure, reasonable. A handy all-in-one raintank/graphite-stack (from Grafana's authors) image and psutil and statsd client. procmon.py provides an implementation.



    $ docker run --rm -p 8080:3000 -p 8125:8125/udp raintank/graphite-stack


    Then in another terminal, after starting target process:



    $ sudo apt-get install python-statsd python-psutil # or via pip
    $ python procmon.py -s localhost -f chromium -r 'chromium.*'


    Then opening Grafana at http://localhost:8080, authentication as admin:admin, setting up datasource https://localhost, you can plot a chart like:



    grafana chart



    graphite-stack & telegraf



    Instead of Python script sending the metrics to Statsd, telegraf (and procstat input plugin) can be used to send the metrics to Graphite directly.



    Minimal telegraf configuration looks like:



    [agent]
    interval = "1s"

    [[outputs.graphite]]
    servers = ["localhost:2003"]
    prefix = "testprfx"

    [[inputs.procstat]]
    pid_file = "/path/to/file/with.pid"


    Then run line telegraf --config minconf.conf. Grafana part is the same, except metrics names.



    sysdig



    sysdig (available in Debian and Ubuntu's repos) with sysdig-inspect UI look very promising, providing extremely fine-grained details along with CPU utilisation and RSS, but unfortunately the UI is unable to render them, and sysdig can't filter procinfo event by process at the time of writing. Though, this should be possible with a custom chisel (an sysdig extension written in Lua).






    share|improve this answer


























    • pgrep systemd is giving multiple lines of output, and thus bugs the psrecord, what should be done? I just want to test with any process.

      – EralpB
      Apr 11 '18 at 7:09






    • 1





      @EralpB pgrep --help to the rescue. There's at least --newest and --oldest.

      – saaj
      Apr 11 '18 at 9:03











    • This should be the accepted answer, since it actually gives a memory usage history plot. Note for the psrecord method, Ctrl+C on the psrecord process just quits without saving a plot, you need to end the process-under-test.

      – user2561747
      Jan 26 at 3:03














    40












    40








    40







    psrecord



    The following addresses history graph of some sort. Python psrecord package does exactly this.



    pip install psrecord                             # local user install
    sudo apt-get install python-matplotlib python-tk # for plotting; or via pip


    For single process it's the following (stopped by Ctrl+C):



    psrecord $(pgrep proc-name1) --interval 1 --plot plot1.png


    For several processes the following script is helpful to synchronise the charts:



    #!/bin/bash    
    psrecord $(pgrep proc-name1) --interval 1 --duration 60 --plot plot1.png &
    P1=$!
    psrecord $(pgrep proc-name2) --interval 1 --duration 60 --plot plot2.png &
    P2=$!
    wait $P1 $P2
    echo 'Done'


    Charts look like:
    psrecord example



    memory_profiler



    The package provides RSS-only sampling (plus some Python-specific options). It can also record process with its children processes (see mprof --help).



    pip install memory_profiler
    mprof run /path/to/executable
    mprof plot


    By default this pops up a Tkinter-based (python-tk may be needed) chart explorer which can be exported:



    mprof



    graphite-stack & statsd



    It may seem an overkill for a simple one-off test, but for something like a several-day debugging it's, for sure, reasonable. A handy all-in-one raintank/graphite-stack (from Grafana's authors) image and psutil and statsd client. procmon.py provides an implementation.



    $ docker run --rm -p 8080:3000 -p 8125:8125/udp raintank/graphite-stack


    Then in another terminal, after starting target process:



    $ sudo apt-get install python-statsd python-psutil # or via pip
    $ python procmon.py -s localhost -f chromium -r 'chromium.*'


    Then opening Grafana at http://localhost:8080, authentication as admin:admin, setting up datasource https://localhost, you can plot a chart like:



    grafana chart



    graphite-stack & telegraf



    Instead of Python script sending the metrics to Statsd, telegraf (and procstat input plugin) can be used to send the metrics to Graphite directly.



    Minimal telegraf configuration looks like:



    [agent]
    interval = "1s"

    [[outputs.graphite]]
    servers = ["localhost:2003"]
    prefix = "testprfx"

    [[inputs.procstat]]
    pid_file = "/path/to/file/with.pid"


    Then run line telegraf --config minconf.conf. Grafana part is the same, except metrics names.



    sysdig



    sysdig (available in Debian and Ubuntu's repos) with sysdig-inspect UI look very promising, providing extremely fine-grained details along with CPU utilisation and RSS, but unfortunately the UI is unable to render them, and sysdig can't filter procinfo event by process at the time of writing. Though, this should be possible with a custom chisel (an sysdig extension written in Lua).






    share|improve this answer















    psrecord



    The following addresses history graph of some sort. Python psrecord package does exactly this.



    pip install psrecord                             # local user install
    sudo apt-get install python-matplotlib python-tk # for plotting; or via pip


    For single process it's the following (stopped by Ctrl+C):



    psrecord $(pgrep proc-name1) --interval 1 --plot plot1.png


    For several processes the following script is helpful to synchronise the charts:



    #!/bin/bash    
    psrecord $(pgrep proc-name1) --interval 1 --duration 60 --plot plot1.png &
    P1=$!
    psrecord $(pgrep proc-name2) --interval 1 --duration 60 --plot plot2.png &
    P2=$!
    wait $P1 $P2
    echo 'Done'


    Charts look like:
    psrecord example



    memory_profiler



    The package provides RSS-only sampling (plus some Python-specific options). It can also record process with its children processes (see mprof --help).



    pip install memory_profiler
    mprof run /path/to/executable
    mprof plot


    By default this pops up a Tkinter-based (python-tk may be needed) chart explorer which can be exported:



    mprof



    graphite-stack & statsd



    It may seem an overkill for a simple one-off test, but for something like a several-day debugging it's, for sure, reasonable. A handy all-in-one raintank/graphite-stack (from Grafana's authors) image and psutil and statsd client. procmon.py provides an implementation.



    $ docker run --rm -p 8080:3000 -p 8125:8125/udp raintank/graphite-stack


    Then in another terminal, after starting target process:



    $ sudo apt-get install python-statsd python-psutil # or via pip
    $ python procmon.py -s localhost -f chromium -r 'chromium.*'


    Then opening Grafana at http://localhost:8080, authentication as admin:admin, setting up datasource https://localhost, you can plot a chart like:



    grafana chart



    graphite-stack & telegraf



    Instead of Python script sending the metrics to Statsd, telegraf (and procstat input plugin) can be used to send the metrics to Graphite directly.



    Minimal telegraf configuration looks like:



    [agent]
    interval = "1s"

    [[outputs.graphite]]
    servers = ["localhost:2003"]
    prefix = "testprfx"

    [[inputs.procstat]]
    pid_file = "/path/to/file/with.pid"


    Then run line telegraf --config minconf.conf. Grafana part is the same, except metrics names.



    sysdig



    sysdig (available in Debian and Ubuntu's repos) with sysdig-inspect UI look very promising, providing extremely fine-grained details along with CPU utilisation and RSS, but unfortunately the UI is unable to render them, and sysdig can't filter procinfo event by process at the time of writing. Though, this should be possible with a custom chisel (an sysdig extension written in Lua).







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jun 7 '18 at 20:52

























    answered Jan 4 '18 at 13:38









    saajsaaj

    53144




    53144













    • pgrep systemd is giving multiple lines of output, and thus bugs the psrecord, what should be done? I just want to test with any process.

      – EralpB
      Apr 11 '18 at 7:09






    • 1





      @EralpB pgrep --help to the rescue. There's at least --newest and --oldest.

      – saaj
      Apr 11 '18 at 9:03











    • This should be the accepted answer, since it actually gives a memory usage history plot. Note for the psrecord method, Ctrl+C on the psrecord process just quits without saving a plot, you need to end the process-under-test.

      – user2561747
      Jan 26 at 3:03



















    • pgrep systemd is giving multiple lines of output, and thus bugs the psrecord, what should be done? I just want to test with any process.

      – EralpB
      Apr 11 '18 at 7:09






    • 1





      @EralpB pgrep --help to the rescue. There's at least --newest and --oldest.

      – saaj
      Apr 11 '18 at 9:03











    • This should be the accepted answer, since it actually gives a memory usage history plot. Note for the psrecord method, Ctrl+C on the psrecord process just quits without saving a plot, you need to end the process-under-test.

      – user2561747
      Jan 26 at 3:03

















    pgrep systemd is giving multiple lines of output, and thus bugs the psrecord, what should be done? I just want to test with any process.

    – EralpB
    Apr 11 '18 at 7:09





    pgrep systemd is giving multiple lines of output, and thus bugs the psrecord, what should be done? I just want to test with any process.

    – EralpB
    Apr 11 '18 at 7:09




    1




    1





    @EralpB pgrep --help to the rescue. There's at least --newest and --oldest.

    – saaj
    Apr 11 '18 at 9:03





    @EralpB pgrep --help to the rescue. There's at least --newest and --oldest.

    – saaj
    Apr 11 '18 at 9:03













    This should be the accepted answer, since it actually gives a memory usage history plot. Note for the psrecord method, Ctrl+C on the psrecord process just quits without saving a plot, you need to end the process-under-test.

    – user2561747
    Jan 26 at 3:03





    This should be the accepted answer, since it actually gives a memory usage history plot. Note for the psrecord method, Ctrl+C on the psrecord process just quits without saving a plot, you need to end the process-under-test.

    – user2561747
    Jan 26 at 3:03











    8














    To use that information on a script you can do this:



    calcPercCpu.sh



    #!/bin/bash
    nPid=$1;
    nTimes=10; # customize it
    delay=0.1; # customize it
    strCalc=`top -d $delay -b -n $nTimes -p $nPid
    |grep $nPid
    |sed -r -e "s;ss*; ;g" -e "s;^ *;;"
    |cut -d' ' -f9
    |tr 'n' '+'
    |sed -r -e "s;(.*)[+]$;1;" -e "s/.*/scale=2;(&)/$nTimes/"`;
    nPercCpu=`echo "$strCalc" |bc -l`
    echo $nPercCpu


    use like: calcPercCpu.sh 1234 where 1234 is the pid



    For the specified $nPid, it will measure the average of 10 snapshots of the cpu usage in a whole of 1 second (delay of 0.1s each * nTimes=10); that provides a good and fast accurate result of what is happening in the very moment.



    Tweak the variables to your needs.






    share|improve this answer


























    • Uhm, 10 processes to monitor the cpu usage of 1?

      – xebeche
      Mar 13 at 14:19











    • @xebeche "it will measure the average of 10 snapshots" "nTimes=10; # customize it" :)

      – Aquarius Power
      3 hours ago













    • I meant I don't like the fact that you call 10 processes to retrieve 1 number ($nPercCpu): shell, top, grep, sed, cut ... bc. Many if not all of these you could for instance merge into 1 Sed or Awk script.

      – xebeche
      2 hours ago
















    8














    To use that information on a script you can do this:



    calcPercCpu.sh



    #!/bin/bash
    nPid=$1;
    nTimes=10; # customize it
    delay=0.1; # customize it
    strCalc=`top -d $delay -b -n $nTimes -p $nPid
    |grep $nPid
    |sed -r -e "s;ss*; ;g" -e "s;^ *;;"
    |cut -d' ' -f9
    |tr 'n' '+'
    |sed -r -e "s;(.*)[+]$;1;" -e "s/.*/scale=2;(&)/$nTimes/"`;
    nPercCpu=`echo "$strCalc" |bc -l`
    echo $nPercCpu


    use like: calcPercCpu.sh 1234 where 1234 is the pid



    For the specified $nPid, it will measure the average of 10 snapshots of the cpu usage in a whole of 1 second (delay of 0.1s each * nTimes=10); that provides a good and fast accurate result of what is happening in the very moment.



    Tweak the variables to your needs.






    share|improve this answer


























    • Uhm, 10 processes to monitor the cpu usage of 1?

      – xebeche
      Mar 13 at 14:19











    • @xebeche "it will measure the average of 10 snapshots" "nTimes=10; # customize it" :)

      – Aquarius Power
      3 hours ago













    • I meant I don't like the fact that you call 10 processes to retrieve 1 number ($nPercCpu): shell, top, grep, sed, cut ... bc. Many if not all of these you could for instance merge into 1 Sed or Awk script.

      – xebeche
      2 hours ago














    8












    8








    8







    To use that information on a script you can do this:



    calcPercCpu.sh



    #!/bin/bash
    nPid=$1;
    nTimes=10; # customize it
    delay=0.1; # customize it
    strCalc=`top -d $delay -b -n $nTimes -p $nPid
    |grep $nPid
    |sed -r -e "s;ss*; ;g" -e "s;^ *;;"
    |cut -d' ' -f9
    |tr 'n' '+'
    |sed -r -e "s;(.*)[+]$;1;" -e "s/.*/scale=2;(&)/$nTimes/"`;
    nPercCpu=`echo "$strCalc" |bc -l`
    echo $nPercCpu


    use like: calcPercCpu.sh 1234 where 1234 is the pid



    For the specified $nPid, it will measure the average of 10 snapshots of the cpu usage in a whole of 1 second (delay of 0.1s each * nTimes=10); that provides a good and fast accurate result of what is happening in the very moment.



    Tweak the variables to your needs.






    share|improve this answer















    To use that information on a script you can do this:



    calcPercCpu.sh



    #!/bin/bash
    nPid=$1;
    nTimes=10; # customize it
    delay=0.1; # customize it
    strCalc=`top -d $delay -b -n $nTimes -p $nPid
    |grep $nPid
    |sed -r -e "s;ss*; ;g" -e "s;^ *;;"
    |cut -d' ' -f9
    |tr 'n' '+'
    |sed -r -e "s;(.*)[+]$;1;" -e "s/.*/scale=2;(&)/$nTimes/"`;
    nPercCpu=`echo "$strCalc" |bc -l`
    echo $nPercCpu


    use like: calcPercCpu.sh 1234 where 1234 is the pid



    For the specified $nPid, it will measure the average of 10 snapshots of the cpu usage in a whole of 1 second (delay of 0.1s each * nTimes=10); that provides a good and fast accurate result of what is happening in the very moment.



    Tweak the variables to your needs.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 3 hours ago

























    answered Jun 30 '13 at 4:31









    Aquarius PowerAquarius Power

    1,73532138




    1,73532138













    • Uhm, 10 processes to monitor the cpu usage of 1?

      – xebeche
      Mar 13 at 14:19











    • @xebeche "it will measure the average of 10 snapshots" "nTimes=10; # customize it" :)

      – Aquarius Power
      3 hours ago













    • I meant I don't like the fact that you call 10 processes to retrieve 1 number ($nPercCpu): shell, top, grep, sed, cut ... bc. Many if not all of these you could for instance merge into 1 Sed or Awk script.

      – xebeche
      2 hours ago



















    • Uhm, 10 processes to monitor the cpu usage of 1?

      – xebeche
      Mar 13 at 14:19











    • @xebeche "it will measure the average of 10 snapshots" "nTimes=10; # customize it" :)

      – Aquarius Power
      3 hours ago













    • I meant I don't like the fact that you call 10 processes to retrieve 1 number ($nPercCpu): shell, top, grep, sed, cut ... bc. Many if not all of these you could for instance merge into 1 Sed or Awk script.

      – xebeche
      2 hours ago

















    Uhm, 10 processes to monitor the cpu usage of 1?

    – xebeche
    Mar 13 at 14:19





    Uhm, 10 processes to monitor the cpu usage of 1?

    – xebeche
    Mar 13 at 14:19













    @xebeche "it will measure the average of 10 snapshots" "nTimes=10; # customize it" :)

    – Aquarius Power
    3 hours ago







    @xebeche "it will measure the average of 10 snapshots" "nTimes=10; # customize it" :)

    – Aquarius Power
    3 hours ago















    I meant I don't like the fact that you call 10 processes to retrieve 1 number ($nPercCpu): shell, top, grep, sed, cut ... bc. Many if not all of these you could for instance merge into 1 Sed or Awk script.

    – xebeche
    2 hours ago





    I meant I don't like the fact that you call 10 processes to retrieve 1 number ($nPercCpu): shell, top, grep, sed, cut ... bc. Many if not all of these you could for instance merge into 1 Sed or Awk script.

    – xebeche
    2 hours ago











    6














    I normally use following two :




    1. HP caliper : its very good tool for monitoring processes it you can check call graph and other low level information also. But please note its free only for personal use.


    2. daemontools : a collection of tools for managing UNIX services







    share|improve this answer





















    • 5





      I used daemontools for years. It's great as a supervisor/watchdog for other processes. How does it help you monitor CPU/memory usage for one process?

      – Stefan Lasiewski
      Aug 19 '10 at 4:05
















    6














    I normally use following two :




    1. HP caliper : its very good tool for monitoring processes it you can check call graph and other low level information also. But please note its free only for personal use.


    2. daemontools : a collection of tools for managing UNIX services







    share|improve this answer





















    • 5





      I used daemontools for years. It's great as a supervisor/watchdog for other processes. How does it help you monitor CPU/memory usage for one process?

      – Stefan Lasiewski
      Aug 19 '10 at 4:05














    6












    6








    6







    I normally use following two :




    1. HP caliper : its very good tool for monitoring processes it you can check call graph and other low level information also. But please note its free only for personal use.


    2. daemontools : a collection of tools for managing UNIX services







    share|improve this answer















    I normally use following two :




    1. HP caliper : its very good tool for monitoring processes it you can check call graph and other low level information also. But please note its free only for personal use.


    2. daemontools : a collection of tools for managing UNIX services








    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jan 12 '11 at 11:12









    Tshepang

    26.3k72186264




    26.3k72186264










    answered Aug 17 '10 at 8:59









    HemantHemant

    4,25623238




    4,25623238








    • 5





      I used daemontools for years. It's great as a supervisor/watchdog for other processes. How does it help you monitor CPU/memory usage for one process?

      – Stefan Lasiewski
      Aug 19 '10 at 4:05














    • 5





      I used daemontools for years. It's great as a supervisor/watchdog for other processes. How does it help you monitor CPU/memory usage for one process?

      – Stefan Lasiewski
      Aug 19 '10 at 4:05








    5




    5





    I used daemontools for years. It's great as a supervisor/watchdog for other processes. How does it help you monitor CPU/memory usage for one process?

    – Stefan Lasiewski
    Aug 19 '10 at 4:05





    I used daemontools for years. It's great as a supervisor/watchdog for other processes. How does it help you monitor CPU/memory usage for one process?

    – Stefan Lasiewski
    Aug 19 '10 at 4:05











    2














    If you know process name you can use



    top -p $(pidof <process_name>)





    share|improve this answer



















    • 7





      That's pretty much what the accepted answer, from years ago, and its first comment say.

      – dhag
      Apr 29 '15 at 15:26
















    2














    If you know process name you can use



    top -p $(pidof <process_name>)





    share|improve this answer



















    • 7





      That's pretty much what the accepted answer, from years ago, and its first comment say.

      – dhag
      Apr 29 '15 at 15:26














    2












    2








    2







    If you know process name you can use



    top -p $(pidof <process_name>)





    share|improve this answer













    If you know process name you can use



    top -p $(pidof <process_name>)






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Apr 29 '15 at 15:03









    user4757345user4757345

    2002211




    2002211








    • 7





      That's pretty much what the accepted answer, from years ago, and its first comment say.

      – dhag
      Apr 29 '15 at 15:26














    • 7





      That's pretty much what the accepted answer, from years ago, and its first comment say.

      – dhag
      Apr 29 '15 at 15:26








    7




    7





    That's pretty much what the accepted answer, from years ago, and its first comment say.

    – dhag
    Apr 29 '15 at 15:26





    That's pretty much what the accepted answer, from years ago, and its first comment say.

    – dhag
    Apr 29 '15 at 15:26











    1














    If you have a cut-down Linux distribution where top does not have per process (-p) option or related options, you can parse the output of the top command for your process name to get the CPU usage information per process.



    while true;  do top -bn1 | awk '/your_process_name/ {print  $8}' ; sleep 1; done


    8 represents the CPU usage per process in the output of the top command in my embedded Linux distribution






    share|improve this answer






























      1














      If you have a cut-down Linux distribution where top does not have per process (-p) option or related options, you can parse the output of the top command for your process name to get the CPU usage information per process.



      while true;  do top -bn1 | awk '/your_process_name/ {print  $8}' ; sleep 1; done


      8 represents the CPU usage per process in the output of the top command in my embedded Linux distribution






      share|improve this answer




























        1












        1








        1







        If you have a cut-down Linux distribution where top does not have per process (-p) option or related options, you can parse the output of the top command for your process name to get the CPU usage information per process.



        while true;  do top -bn1 | awk '/your_process_name/ {print  $8}' ; sleep 1; done


        8 represents the CPU usage per process in the output of the top command in my embedded Linux distribution






        share|improve this answer















        If you have a cut-down Linux distribution where top does not have per process (-p) option or related options, you can parse the output of the top command for your process name to get the CPU usage information per process.



        while true;  do top -bn1 | awk '/your_process_name/ {print  $8}' ; sleep 1; done


        8 represents the CPU usage per process in the output of the top command in my embedded Linux distribution







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 3 '17 at 5:45

























        answered Mar 3 '17 at 5:37









        Razan PaulRazan Paul

        1214




        1214























            0














            If you need the averages for a period of time of a specific process, try the accumulative -c option of top:



            top -c a -pid PID


            "-c a" found in top for Mac 10.8.5.



            For Scientific Linux, the option is -S, that can be set interactively.






            share|improve this answer


























            • You'll likely want to add further details around which version(s) of top actually provide this feature. My version on Fedora 19 does not. Same too on Ubuntu 13.04.

              – slm
              May 12 '14 at 1:22











            • You're right!, I was so happy of having found something useful, I forgot I was in my mac at home.

              – Kieleth
              May 13 '14 at 19:34
















            0














            If you need the averages for a period of time of a specific process, try the accumulative -c option of top:



            top -c a -pid PID


            "-c a" found in top for Mac 10.8.5.



            For Scientific Linux, the option is -S, that can be set interactively.






            share|improve this answer


























            • You'll likely want to add further details around which version(s) of top actually provide this feature. My version on Fedora 19 does not. Same too on Ubuntu 13.04.

              – slm
              May 12 '14 at 1:22











            • You're right!, I was so happy of having found something useful, I forgot I was in my mac at home.

              – Kieleth
              May 13 '14 at 19:34














            0












            0








            0







            If you need the averages for a period of time of a specific process, try the accumulative -c option of top:



            top -c a -pid PID


            "-c a" found in top for Mac 10.8.5.



            For Scientific Linux, the option is -S, that can be set interactively.






            share|improve this answer















            If you need the averages for a period of time of a specific process, try the accumulative -c option of top:



            top -c a -pid PID


            "-c a" found in top for Mac 10.8.5.



            For Scientific Linux, the option is -S, that can be set interactively.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited May 13 '14 at 19:32

























            answered May 11 '14 at 22:09









            KielethKieleth

            111




            111













            • You'll likely want to add further details around which version(s) of top actually provide this feature. My version on Fedora 19 does not. Same too on Ubuntu 13.04.

              – slm
              May 12 '14 at 1:22











            • You're right!, I was so happy of having found something useful, I forgot I was in my mac at home.

              – Kieleth
              May 13 '14 at 19:34



















            • You'll likely want to add further details around which version(s) of top actually provide this feature. My version on Fedora 19 does not. Same too on Ubuntu 13.04.

              – slm
              May 12 '14 at 1:22











            • You're right!, I was so happy of having found something useful, I forgot I was in my mac at home.

              – Kieleth
              May 13 '14 at 19:34

















            You'll likely want to add further details around which version(s) of top actually provide this feature. My version on Fedora 19 does not. Same too on Ubuntu 13.04.

            – slm
            May 12 '14 at 1:22





            You'll likely want to add further details around which version(s) of top actually provide this feature. My version on Fedora 19 does not. Same too on Ubuntu 13.04.

            – slm
            May 12 '14 at 1:22













            You're right!, I was so happy of having found something useful, I forgot I was in my mac at home.

            – Kieleth
            May 13 '14 at 19:34





            You're right!, I was so happy of having found something useful, I forgot I was in my mac at home.

            – Kieleth
            May 13 '14 at 19:34


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f554%2fhow-to-monitor-cpu-memory-usage-of-a-single-process%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Entries order in /etc/network/interfaces

            新発田市

            Grub takes very long (several minutes) to open Menu (in Multi-Boot-System)