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*

4
  • 1
    Helped me when trying to kill non existing processes to prevent the kill foo_pid failed: no such process message Commented Aug 12, 2012 at 12:58
  • @Koen. Yes, but this has nothing do with background jobs. You can silence any error message issued by kill itself - as with any command - with 2>/dev/null. The reason this answer isn't effective with background jobs is that Bash itself asynchronously, after the kill command has completed, outputs a status message about the killed job, which you cannot suppress directly - unless you use wait, as in the accepted answer. Commented Jul 11, 2016 at 4:03
  • @mklement0 I actually tried this today to find that only kill $foo_pid 2>/dev/null worked in silencing the error messages. Commented Jan 8, 2022 at 1:15
  • @Alaska, as far as I can tell, the problem only occurs when the kill command is used to kill a job interactively. Inside scripts job-control messages such as the shown in the question do not print (unless you source the script from the interactive prompt). (This contradicts the question). In other words: if you call kill $foo_pid from a (non-sourced) script, kill $foo_pid 2>/dev/null is sufficient (to cover the case where $foo_pid no longer exists). Interactively (or in a script sourced interactively), you need { kill $foo_pid && wait $foo_pid; } 2>/dev/null Commented Jan 8, 2022 at 3:07