7

I want to monitor running python processes with VSZ, RSS %MEM, %CPU etc. One of my priorities is a list refreshing every X seconds. I managed to come to the point of obtaining a refreshing list of processes using ps and watch

ps ax | grep python | awk '{print $1}' | xargs watch -n 15 ps u -p

That command simply find all the processes which includes python in its command line in ps and pass the pid values to watch.

ps u -p 9221 10186 11640 12347 14076 14263 14317 19029 22099 24278 26161 32469

It is all fine, but that command evaluates the pid list only once and keep watching those pids. What I need is executing ps ax | grep python command every X seconds and get a fresh list of running processes. That Way, I can see which process has started and which one had finished executing.

2 Answers 2

19

You can watch any command so give this a try

watch "ps aux | grep python"

3
  • That command do not list all the processes, but only (this is my guess) the ones that are started on current session. I want to watch port listening python processes and some of the are running for weeks.
    – Mp0int
    Commented Jul 28, 2015 at 9:08
  • 1
    Then use watch "ps aux | grep python"
    – coteyr
    Commented Jul 28, 2015 at 9:09
  • 1
    The point is getting the list of PIDs is not needed, you can just watch the output of a greped ps.
    – coteyr
    Commented Jul 28, 2015 at 9:10
5

You can also use top instead of watch:

top -p $(ps ax | grep python | awk '{print $1}' | paste -sd "," -) -d 2
3
  • That was a great way too, but is it possible to see the process command line since I can only see that it is a python process but can not understand
    – Mp0int
    Commented Jul 28, 2015 at 9:23
  • Yes you can: add -c option to end of line like: top -p ... -d 2 -c
    – ErrieR
    Commented Jul 28, 2015 at 9:31
  • Ah, that is excellent (:
    – Mp0int
    Commented Jul 28, 2015 at 9:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .