Karl Karl - 4 months ago 5x
Linux Question

How can i have exit status of zero with kill command

I am using this command to kill

ps aux | bla bla | xargs kill -9

It's working fine but the problem is it also sometimes tries to kill subprocess id which already got killed because of parent process kill so it returns as non zero exit status.

Is there any way to make as exit status 0?


The trivial way is to just ignore any non-zero exit status:

ps aux | bla bal | xargs kill || true

(You probably shouldn't be using kill -9; it's a debugging tool, not intended for production use.)