Using ps to Monitor Processes


In a previous tech tip, we saw how to use kill to monitor processes. Another option is to use ps. With both methods, you can check $? for success/failure. However, note that kill -0 may return failure even if the process actually exists. This happens when the current user has no permission to the process in question, for example: kill -0 1.

To check for a process silently (with no output), use:

kill -0 PID 2>/dev/null
ps -p PID >/dev/null


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

I tend to use the command

Anonymous's picture

I tend to use the command "pgrep process-pattern". It seems to do the trick as well and has many options to tailor command behaviour.

I like this how2

Anonymous's picture

I like this how2