Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
share|improve this question

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

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

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

4 Answers 4

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

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
share|improve this answer
taskid=12345

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.