The Kill and Killall commands in Linux

- Andrés Cruz

En español
The Kill and Killall commands in Linux

Depending on the Linux distribution you use, its version, installed programs, computer resources among other agents, many things can go wrong that cause the computer to "hang" or at least some program in question (it happens quite often with programs resource-intensive ones like Eclipse, Android Studio, emulators, etc.).

In these cases the right thing to do is simply "kill" or destroy the process(es) associated with the program in order to free up resources and possibly start the program again.

The Kill and Killall commands to "kill" processes

There are a couple of commands that allow you to perform this task in a simple way; they are Kill and Killall.

The kill command

To use the Kill command it is necessary to know the identifier of the process that we want to kill or destroy; for this we use the ps aux command:

...
3036 ?        S      0:00 /opt/google/chrome/chrome --type=zygote --enable-crash-reporter=DFD73122-B4B8-416D-A254-9ABF21A8B36E
 3056 ?        Sl     4:35 /proc/self/exe --type=gpu-process --channel=3019.0.65190361 --enable-crash-reporter=DFD73122-B4B8-416D-A254-9ABF2
 3062 ?        S      0:00 /proc/self/exe --type=gpu-process --channel=3019.0.65190361 --enable-crash-reporter=DFD73122-B4B8-416D-A254-9ABF2
 3145 ?        Sl     0:08 /opt/google/chrome/chrome --type=renderer --lang=es-419 --force-fieldtrials=AffiliationBasedMatching/Enabled/Audi
 3149 ?        Sl     0:00 /opt/google/chrome/chrome --type=renderer --lang=es-419 --force-fieldtrials=AffiliationBasedMatching/Enabled/Audi
 3152 ?        Sl     0:00 /opt/google/chrome/chrome --type=renderer --lang=es-419 --force-fieldtrials=AffiliationBasedMatching/Enabled/Audi
 3225 ?        Sl     0:00 /usr/libexec/gvfsd-trash --spawner :1.5 /org/gtk/gvfs/exec_spaw/0
 3268 ?        Sl     1:01 /opt/google/chrome/chrome --type=renderer --lang=es-419 --force-fieldtrials=AffiliationBasedMatching/Enabled/Audi
 3525 ?        S      0:00 /home/andres/sts-bundle/sts-3.6.4.RELEASE/STS
 3527 ?        Sl     5:07 /usr/bin/java -Dosgi.requiredJavaVersion=1.6 -Xms40m -Xmx768m -XX:MaxPermSize=256m -jar /home/andres/sts-bundle/s
 4306 ?        Sl     6:14 /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.60-14.b27.fc21.x86_64/bin/java -Dcatalina.base=/home/andres/sts-bundle/pivo
 4349 ?        Ss     0:02 postgres: postgres oo 127.0.0.1(50352) idle
 4468 ?        Sl     0:17 /opt/google/chrome/chrome --type=renderer --lang=es-419 --force-fieldtrials=*AffiliationBasedMatching/Enabled/Aud
 4510 ?        Sl     0:28 /opt/google/chrome/chrome --type=renderer --lang=es-419 --force-fieldtrials=*AffiliationBasedMatching/Enabled/Aud
 5568 ?        Sl     0:16 /opt/google/chrome/chrome --type=renderer --lang=es-419 --force-fieldtrials=*AffiliationBasedMatching/Enabled/Aud
 5624 ?        Ss     0:04 postgres: postgres oo 127.0.0.1(51676) idle
 6278 ?        Sl     0:02 /usr/bin/nautilus --gapplication-service
 7712 ?        Sl     0:03 /usr/bin/pgadmin3
 8133 ?        Sl     0:49 /opt/google/chrome/chrome --type=renderer --lang=es-419 --force-fieldtrials=*AffiliationBasedMatching/Enabled/Aud
 8207 ?        Sl     0:40 /opt/google/chrome/chrome --type=ppapi --channel=3019.108.1263279707 --ppapi-flash-args --lang=es-419 --enable-cr
 8381 ?        S      0:00 [kworker/u4:2]
 8600 ?        S      0:01 [kworker/1:0]
 9268 ?        S      0:00 [kworker/0:3]
 9545 ?        Sl     0:00 /opt/google/chrome/chrome --type=renderer --lang=es-419 --force-fieldtrials=*AffiliationBasedMatching/Enabled/Aud
 9582 ?        S      0:00 [kworker/1:2]
 9622 ?        Sl     0:00 /opt/google/chrome/chrome --type=renderer --lang=es-419 --force-fieldtrials=*AffiliationBasedMatching/Enabled/Aud
 9629 ?        Sl     0:02 /opt/google/chrome/chrome --type=renderer --lang=es-419 --force-fieldtrials=*AffiliationBasedMatching/Enabled/Aud
 9642 ?        Sl     0:00 /opt/google/chrome/chrome --type=ppapi --channel=3019.137.1613879471 --ppapi-flash-args --lang=es-419 --enable-cr
 9650 ?        Sl     1:12 /opt/google/chrome/chrome --type=renderer --lang=es-419 --force-fieldtrials=*AffiliationBasedMatching/Enabled/Aud
 9873 ?        S      0:00 [kworker/0:0]
 9876 ?        S      0:00 [kworker/u4:0]
 9967 ?        Rl     0:00 /usr/libexec/gnome-terminal-server
 9970 ?        S      0:00 gnome-pty-helper
 9971 pts/0    Ss     0:00 bash
10051 ?        Sl     0:01 /opt/google/chrome/chrome --type=renderer --lang=es-419 --force-fieldtrials=*AffiliationBasedMatching/Enabled/Aud
10078 ?        S      0:00 [kworker/0:1]
10081 ?        Sl     0:00 /usr/bin/gedit --gapplication-service
10088 ?        S      0:00 [kworker/u4:1]
...

Filtering processes with the ps and grep command

Although to our surprise, there are too many processes managed by the system that were not necessarily started by us and are part of the system; to filter them we can use the ps command in conjunction with the grep command as follows:

ps aux | grep gedit

This gives us a much smaller list:

andres   10081  0.3  0.7 666388 35004 ?        Sl   11:21   0:00 /usr/bin/gedit --gapplication-service andres   10231  0.0  0.0 113020  2248 pts/0    S+   11:24   0:00 grep --color=auto gedit

Now we can kill the Gedit program associated with process ID 10081 (PDI) (as we can see in the output returned above) by simply running the following command:

kill 10081

If the process does not exist, we will see an output similar to the following:

kill 41076
bash: kill: (41076) - No existe el proceso

The command syntax:

kill PDI

The Killall Command

With the Killall command it is easier, just knowing the name of the process that we want to kill is enough; for example, to kill him; to kill the process named "firefox":

killall firefox

To kill the process "gedit":

killall gedit

To kill the process "pgadmin3":

killall pgadmin3

To kill the process "google-chrome":

killall google-chrome

To kill the process "nautilus":

killall nautilus

To kill the process ("pgadmin3" in this example) does not exist, we will see output similar to the following:

killall pgadmin3
pgadmin3: no process found

How can you tell, it is necessary to know the name of the process you want to kill from the system to use the commando Killall.

Andrés Cruz

Desarrollo con Laravel, Django, Flask, CodeIgniter, HTML5, CSS3, MySQL, JavaScript, Vue, Android, iOS, Flutter

Andrés Cruz en Udemy

Acepto recibir anuncios de interes sobre este Blog.