Reputation: 3113
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?
Upvotes: 2
Views: 2269
Reputation: 22646
The accepted solution des did not work for me everywhere.
The following simple, one-line solution works fine with all kinds of Linux/Unix. I tested it with Ubuntu, Mint, Centos, Amazon Linux, and Alpine (Docker).
This runs in a new shell and this way you can control properly the exit code.
/bin/bash -c '/usr/bin/killall -q <process-name>; exit 0'
Upvotes: 0
Reputation: 530843
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.)
Upvotes: 3