Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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 '15 at 11:52

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

You must log in to answer this question.