≡ Menu

UNIX / Linux: Kill All My Jobs Under Current Shell Session

How do I kill all the UNIX jobs I created under my current login shell such as Bash or KSH before logout?

All your jobs running in background or suspended mode can be listed with the job command. Open a command-line terminal (select Applications > Accessories > Terminal), and then type the following to examine the current jobs list:
$ jobs
Sample outputs:

[1]-  Running                 ping google.com > /dev/null &
[2]+  Stopped                 ftp ftp.freebsd.org
[3]-  Running                 rsync -ar vivek@r.lan.vip.nixcraft.net.in:/backup/tree/ ~/.tree/ >/dev/null &

To list its PIDs, enter:
$ jobs -p
Sample outputs:


To kill all the jobs running under the ksh or bash shell, enter:
$ kill `jobs -p`
$ kill $(jobs -p)
You can also kill single job using pid. For example, kill ftp ftp.freebsd.org job having PID # 6021 as follows:
$ kill -9 6021
Sample outputs (hit [Enter] key to processed):

[2]+  Killed                  ftp ftp.freebsd.org