Another question I am asked frequently.
!!! W A R N I N G! DANGER WILL ROBINSON! W A R N I N G !!!
NOTE: USE THIS COMMAND WITH EXTREME CAUTION!!
DO NOT USE THIS COMMAND, IF YOU ARE A N00B
The pkill command is a process kill by name. All processes that match the name given, are terminated.
This is different then the kill command, in that pkill allows you to kill all processes that match the name. kill just allows you to kill one process id (pid)
You might do something like this to get the process name:
ps -ef | grep chrome
I am looking for all chrome browser tasks, but it could be anything.
What the ps command does, (list processes) is give you a snapshot of what tasks are currently running on your system.
The -ef says list ALL the processes, and use the FULL format.
The output is then piped over to grep. Piping means to take the output of one programme, in this case ps, and make that the input to the next programme. grep in our case. (think of grep as a programme that finds things that match inside a file.) grep is the programme following the piping symbol or “|”.
so the above command produces output which looks like:
nwayno@Homer:~$ ps -ef | grep chrome
nwayno 2467 2774 2 Jul09 ? 00:05:01 /opt/google/chrome/chrome –type=zygote
nwayno 2765 1 0 Jul09 ? 00:08:43 /opt/google/chrome/chrome
nwayno 2772 2765 0 Jul09 ? 00:00:06 /opt/google/chrome/chrome
nwayno 2774 1 0 Jul09 ? 00:00:00 /opt/google/chrome/chrome –type=zygote
nwayno 2802 2774 0 Jul09 ? 00:00:12 /opt/google/chrome/chrome –type=zygote
nwayno 2805 2774 0 Jul09 ? 00:01:52 /opt/google/chrome/chrome –type=zygote
nwayno 2809 2774 0 Jul09 ? 00:00:15 /opt/google/chrome/chrome –type=zygote
nwayno 2811 2774 0 Jul09 ? 00:00:19 /opt/google/chrome/chrome –type=zygote
nwayno 2822 2774 0 Jul09 ? 00:00:01 /opt/google/chrome/chrome –type=zygote
nwayno 21980 2774 2 00:45 ? 00:00:10 /opt/google/chrome/chrome –type=zygote
nwayno 22325 22292 0 00:52 pts/6 00:00:00 grep chrome
nwayno 31015 2765 7 Jul09 ? 00:22:09 /opt/google/chrome/chrome –type=plugin –plugin-path=/usr/lib/mozilla/plugins/libflashplayer.so –lang=en-US –channel=2765.0x40f2b00.2139444310
to kill all the processes:
!!! W A R N I N G! DANGER WILL ROBINSON! W A R N I N G !!!
NOTE: USE THIS COMMAND WITH EXTREME CAUTION!!
DO NOT USE THIS COMMAND, IF YOU ARE A N00B
sudo pkill chrome
Would kill all the above chrome tasks. How do we know if the processes are gone?
ps -ef | grep chrome
Just returns a prompt:
nwayno@Homer:~$ ps -ef | grep chrome
nwayno@Homer:~$
Incidentally, there is NO pkill -9 command. But there is a kill -9 command! Use man to find the difference.
Wayno
Related Articles
No user responded in this post