Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

15
  • 7
    The process could have exited between ps and kill. Commented Aug 27 at 18:54
  • 5
    Why bother checking first? Just try to kill them and ignore the errors when they don't exist. Commented Aug 27 at 18:58
  • 3
    ... possibly as a result of the process previous to it in the list dying. Commented Aug 27 at 18:58
  • 2
    In addition to @Barmar 's comment on "why bother checking?", if you are going to check then using kill =0 rather than ps -p is a lot cheaper way to do the check. Of course once you have the two kill commands it becomes even more obvious that you probably don't need the test. Commented Aug 27 at 19:07
  • @Barmar if I add a condition to check whether process still exists after killing the process, the if ps -p $pid > /dev/null; condition is returning true, which I am not getting Commented Aug 28 at 4:09