Simply kill $( jobs -p ) not work in dash.
For example in dash:

$ sleep 999 &
$ kill $(jobs -p)
dash: 2: kill: Usage: kill [-s sigspec | -signum | -sigspec] [pid | job]... or
kill -l [exitstatus]
  • 1
    Are you really using dash as an interactive shell, or did you happen upon this when trying to debug some script? Notice that that kill $(jobs -p) will not kill all the background jobs, but only the job/program group leaders: even in bash, if you run (sleep 3600; echo DONE) &, and then kill $(jobs -p), the sleep process will not be killed. – mosvy Dec 25 '19 at 23:35
  • 1
    Anyways, you can run jobs -p > tmpfile; kill $(cat tmpfile) -- and that's the very best Q you can get while not questioning any of the dubious assumptions ;-) – mosvy Dec 25 '19 at 23:44
  • 1
    Then you'll have to make do with copy&paste, a temporary file or a named pipe. Just in case it wasn't clear from my 1st comment, the linked stackoverflow answer is incorrect, as kill $(jobs -p) will not kill all the background processes or jobs. – mosvy Dec 26 '19 at 23:31
  • 1
    If you want to kill all the processes from the current session, use pkill -s0; but if your interractive shell you call that from is not the session leader, that may also kill processes not started from it. – mosvy Dec 26 '19 at 23:35
  • 1
    Do it backwards, run the kill asynchronously. (kill -TERM $(sed s/^/-/ fifo)&); jobs -p > fifo – mosvy Dec 28 '19 at 0:03

Make a bug report to the maintainers of dash.

It seems that dash does return empty output in case that jobs is run in a subshell.

Do you really need to use dash? It is know for not being POSIX compliant for several reasons.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.