Kill a Process by Name in Linux



This article shows you how to use the Linux pkill command to kill running processes within Linux by using a name. Pkill (see pgrep) is a command-line utility while Solaris 7 process is running. pkill works on a currently active running process and lists down process ID’s which matches with the criteria.

To kill a process by name in Linux, use the following command –

pkill

To get a list of process in Linux, use the following command –

$ ps -A

The sample output should be like this –

PID TTY          TIME CMD
   1 ?           00:00:01 systemd
   2 ?           00:00:00 kthreadd
   3 ?           00:00:00 ksoftirqd/0
   5 ?           00:00:00 kworker/0:0H
   7 ?           00:00:17 rcu_sched
   8 ?           00:00:00 rcu_bh
   9 ?           00:00:00 migration/0
   10 ?          00:00:00 watchdog/0
   11 ?          00:00:00 watchdog/1
   12 ?          00:00:00 migration/1
   13 ?          00:00:00 ksoftirqd/1
   15 ?          00:00:00 kworker/1:0H
   16 ?          00:00:00 watchdog/2
   17 ?          00:00:00 migration/2
   18 ?          00:00:00 ksoftirqd/2
   20 ?          00:00:00 kworker/2:0H
   21 ?          00:00:00 watchdog/3
   22 ?          00:00:00 migration/3
   23 ?          00:00:00 ksoftirqd/3
   25 ?          00:00:00 kworker/3:0H
   26 ?          00:00:00 kdevtmpfs
   27 ?          00:00:00 netns
   28 ?          00:00:00 perf
   29 ?          00:00:00 khungtaskd
   30 ?          00:00:00 writeback
   31 ?          00:00:00 ksmd
   32 ?          00:00:00 khugepaged
   33 ?          00:00:00 crypto
   34 ?          00:00:00 kintegrityd
   35 ?          00:00:00 bioset
   36 ?          00:00:00 kblockd
   37 ?          00:00:00 ata_sff
   38 ?          00:00:00 md
   39 ?          00:00:00 devfreq_wq
   44 ?          00:00:00 kswapd0
   45 ?          00:00:00 vmstat
   46 ?          00:00:00 fsnotify_mark
   47 ?          00:00:00 ecryptfs-kthrea
   63 ?          00:00:00 kthrotld
   64 ?          00:00:00 acpi_thermal_pm
   65 ?          00:00:00 bioset
   66 ?          00:00:00 bioset
   67 ?          00:00:00 bioset
...............................................

To kill the process using name, use the following command –

$sudo pkill apache2

To verify the above command, use the following command –

$ ps -A

From the above, we have learnt about – How to Kill a Process by Name in Linux? We will come up with more Linux based tricks and tips. Keep reading!

Updated on: 2020-01-22T08:08:36+05:30

644 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements