Quote:
Originally Posted by
redhead
which is exactly why it is extensively used in combination with grep, in order to make it work no matter what teh underlying system supports in the ps command.
It may work, mostly, regardless of the underlying system, but it's not a robust solution. False positives remain a possibility and could result in killing the wrong process or mistakenly concluding that a dead process is still running.
A few years ago I helped someone troubleshoot an intermittent failure which I found to be caused by grepping ps output for a short command name which sometimes occured as a substring in a related command's arguments.
You could improve the situation by tightening up the regular expression a bit, or perhaps using AWK to search for the term in a specific field, but at that point you may be depending on non-portable output format characteristics. May as well make life easier and just use the non-portable ps options.
For this task, I'm not sure you can achieve portability and correctness using ps. I think with pgrep you can, but I haven't taken a close look at many pgrep implementations. That said, I realize that many systems and tasks are not mission critical, and so an 80% solution is often sufficient.
PID files? Mostly useless and racy.
Quote:
Originally Posted by William Wallace -- Scottish Sysadmin
"They may take our lives, but they'll never take... OUR P{GREP,KILL}!!!"
Okay, maybe I went a little off the rails there.
Regards,
Alister