I got a parent and a child process running, I know their IDs.

How do I utilize 'ps' and 'watch' to filter them out, so that I can see their used CPU times?

I tried 'watch ps -u USERNAME', but as you can imagine there are a lot more processes than the desired ones.


If the PIDs are e.g. 340 and 520, then you can try the following:

$ watch --interval 2 --difference "ps -p 340,520 -o pid,ppid,%cpu,cputime"

Here watch will mark the difference of outputs running with 2 seconds interval, here we have used the output formatting -o option to get only process ID (pid), parent process ID (ppid), percentage of cpu utilization (%cpu) and the cpu time (cputime).

Check man ps for more ps output formatting options.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.