How to tell the kill command to ignore processes if that process is not alive?

For example: 3453 is an alive process but 44534 is not.

kill -9 3453 44534
link|improve this question
1  
Also, what you're asking is not quite clear. Could you rephrase or elaborate to say exactly what you want to happen? – lc. Jun 18 '10 at 12:13
feedback

migrated from stackoverflow.com Jun 18 '10 at 12:15

This question came from our site for professional and enthusiast programmers.

4 Answers

kill -9 3453 || kill -9 44535
link|improve this answer
And what if the situation were reversed? Or if both are alive? – Ignacio Vazquez-Abrams Jun 23 '10 at 20:23
feedback

Most people are not aware that kill is a built-in command for many shells and I am assuming that you are using bash and that you would like to suppress the "no such process" messages that may be generated. The executable located in /bin/kill on one of my machines generates no such messages.

$ /bin/kill -9 3453 44534
link|improve this answer
feedback
taskid=12345

if ps ax | grep -v grep | grep $taskid > /dev/null; then
  kill -9 $taskid
  # Task killed
fi
link|improve this answer
feedback
for pid in 3453 44534
do
  kill -9 "$pid" > /dev/null 2> /dev/null || :
done
link|improve this answer
feedback

Your Answer

 
or
required, but never shown