How to kill all background processes in zsh?

d33tah picture d33tah · Oct 31, 2012 · Viewed 7.5k times · Source

As in the title - how to kill all background processes in zsh?

Answer

ZyX picture ZyX · Oct 31, 2012
alias killbg='kill ${${(v)jobstates##*:*:}%=*}'

. It is zsh, no need in external tools.

If you want to kill job number N:

function killjob()
{
    emulate -L zsh
    for jobnum in $@ ; do
        kill ${${jobstates[$jobnum]##*:*:}%=*}
    done
}
killjob N