Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to kill all background processes in zsh?

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

like image 839
d33tah Avatar asked Oct 31 '12 19:10

d33tah


People also ask

How do I close all background processes?

To end all background processes, go to Settings, Privacy, and then Background Apps. Turn off the Let apps run in the background. To end all Google Chrome processes, go to Settings and then Show advanced settings. Kill all related processes by unchecking Continue running background apps when Google Chrome is closed.

How do you kill all jobs in terminal?

The killall command kills a running process by name, rather than by process ID. If there are multiple instances of a particular command running, then doing a killall on that command will terminate them all. This refers to the killall command in /usr/bin, not the killall script in /etc/rc.

How do you kill a background job?

To cancel a background job, use the kill command. To be able to kill a process, you must own it. (The superuser, however, can kill any process except init.) Before you can cancel a background job, you need to know either a PID, job identifier, or PGID.


1 Answers

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
like image 60
ZyX Avatar answered Oct 23 '22 16:10

ZyX