Sign up ×
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 Jun 18 '10 at 12:15

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

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
for pid in 3453 44534
  kill -9 "$pid" > /dev/null 2> /dev/null || :
share|improve this answer

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
and it also generates error... – OZ_ Nov 8 at 11:52

if ps ax | grep -v grep | grep $taskid > /dev/null; then
  kill -9 $taskid
  # Task killed
share|improve this answer

Your Answer


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