Linux101 Find and Kill a Process
List all the processes
Two approaches are demonstrated below:
$ ps -ef
……
$ smx 1822 1 0 11:38 ? 00:00:49 gnome-terminal
$ smx 1823 1822 0 11:38 ? 00:00:00 gnome-pty-helper
$ smx 1824 1822 0 11:38 pts/0 00:00:02 bash
$ smx 1827 1 4 11:38 ? 00:26:28 /usr/lib/firefox-3.6.18/firefox-bin
$ smx 1857 1822 0 11:38 pts/1 00:00:00 bash
$ smx 1880 1619 0 11:38 ? 00:00:00 update-notifier
……
$ smx 11946 1824 0 21:41 pts/0 00:00:00 ps -ef
Or:
$ ps -aux
……
$ smx 1822 0.1 0.8 58484 18152 ? Sl 11:38 0:49 gnome-terminal
$ smx 1823 0.0 0.0 1988 712 ? S 11:38 0:00 gnome-pty-helper
$ smx 1824 0.0 0.1 6820 3776 pts/0 Ss 11:38 0:02 bash
$ smx 1827 4.3 5.8 398196 119568 ? Sl 11:38 26:13 /usr/lib/firefox-3.6.18/firefox-bin
$ smx 1857 0.0 0.1 6688 3644 pts/1 Ss 11:38 0:00 bash
$ smx 1880 0.0 0.6 41536 12620 ? S 11:38 0:00 update-notifier
……
$ smx 11953 0.0 0.0 2716 1064 pts/0 R+ 21:42 0:00 ps -aux
Kill a Target Process
Suppose we want to determinate Firefox. To kill it, type and run:
$ kill -s 9 `ps -aux | grep firefox | awk '{print $2}'`
Step 1. ps -aux lists all the processes.
Step 2. grep firefox takes as input the process list generated by the command of Step 1. and select out all the Firefox related processes.
Step 3. awk {print $2} prints the second column of the result generated by the command of Step 2. That is, the PIDs related to Firefox and leave it as the input argument for the final command kill -s 9.
This is what the killing one-liner is. Dont!
References
| [1] | Find and kill a process in one line using bash and regex |
|---|---|
| [2] | linux 查看某进程 并杀死进程 ps grep kill |