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:

ADVERTISEMENTS

[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:

6020
6021
6023

To kill all the jobs running under the ksh or bash shell, enter:
$ kill `jobs -p`
OR
$ 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
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.