The Kill and Killall commands in Linux: how to kill processes correctly

- Andrés Cruz

ES En español

The Kill and Killall commands in Linux: how to kill processes correctly

If you use Linux, surely it has happened to you: your computer becomes slow, Eclipse freezes, Android Studio doesn't respond, or even Chrome starts behaving strangely. This happens when a process consumes too many resources or gets stuck. The solution: “kill” the process to free up memory and CPU, and be able to keep working without restarting the system.

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 a specific program (it happens quite often with resource-heavy programs like Android Studio, emulators, Local AIs, XCode, Games etc.).

In these cases, the correct 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.

Killing processes in Linux: basic concepts

In Linux, a process is the execution of a program in memory. To control them, there are tools like kill and killall. Both allow terminating processes, but they work differently and are used in different situations.

The Kill and Killall commands to "kill" processes

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

What is a PID and why it is important

Every process in Linux has a PID (Process ID), a unique number that identifies the running process. Kill needs this PID to know which process to terminate. It is ideal when you want absolute precision, for example, closing a Chrome instance that hung without affecting other instances.

How to get the PID with ps and grep

To locate the PID, you can use:

ps aux | grep process_name

Example, if you want to kill Gedit:

ps aux | grep gedit

This returns something like:

andres   10081  0.3  0.7 666388 35004 ?        Sl   11:21   0:00 /usr/bin/gedit

The PID here is 10081.

Practical example using the Kill command

To use the Kill command, it is necessary to know the identifier of the process 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 returns a much more reduced 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 the process ID 10081 (PID) (as we can see in the output returned above) simply by executing 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 such process

The command syntax:

kill PID

Which signals does kill use and when to use them:

  • SIGTERM (15): terminates the process in an orderly fashion.
  • SIGKILL (9): forces immediate termination.
  • SIGHUP (1): reloads the process configuration.
  • SIGINT (2): interrupts foreground processes (Ctrl+C).
  • In general, try SIGTERM first; only use SIGKILL if there is no other option.

The Killall command

With the Killall command it is simpler, as just knowing the name of the process we want to kill is enough.

Key differences between kill and killall

  • kill: needs PID → precise control.
  • killall: uses process name → closes all instances with that name.

For example, to kill it; to kill the process named "firefox":

killall firefox

To kill the "gedit" process:

killall gedit

To kill the "pgadmin3" process:

killall pgadmin3

To kill the "google-chrome" process:

killall google-chrome

To kill the "nautilus" process:

killall nautilus

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

killall pgadmin3 
pgadmin3: no process found

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

Common mistakes when using killall

  • It is case-sensitive: firefox ≠ Firefox.
  • It can affect multiple unintended instances if you are not careful.
  • Using -9 unnecessarily can cause data loss.

Kill vs Killall: which one to use in each situation

  • Use kill if you want to close a specific process and you know the PID.
  • Use killall if you want to close all instances of a program by its name.
  • On critical systems or servers, always verify which processes you are terminating.

Practical tips for killing processes without breaking the system

  • Always identify the correct PID or name.
  • Avoid kill -9 unless the process is unresponsive.
  • For resource-heavy processes, check with:
    • top
    • or
    • htop
    • Combine ps aux | grep to filter specific processes.

Common errors when killing processes in Linux

  • Killing system processes as root without caution → can crash Linux.
  • Confusing uppercase and lowercase in killall.
  • Not checking child processes → closing the parent also terminates children unexpectedly.

Frequently Asked Questions about kill and killall

  • What is the difference between kill and killall?
    • Kill uses PID → precise control. Killall uses name → closes all instances.
  • What happens if I use kill -9?
    • Forces the closure of the process. Can cause data loss if the process does not save its state.
  • How to know the PID of a process?
    • With ps aux | grep process_name, pidof or pgrep.
  • Is it dangerous to use killall?
    • Yes, it can close several instances without distinction. Use it with care.
  • What command to use if Linux freezes?
    • If the terminal works, killall process_name or kill -9 PID. If the GUI doesn't respond, xkill can be useful.

Conclusion

Mastering kill and killall gives you real control over Linux. You can fix hangs, free up resources, and continue working without rebooting. The combination of kill, killall, pgrep, and top allows you to handle your system safely and efficiently. Remember: first order the closure with SIGTERM, then force only if necessary.

A complete guide to killing processes in Linux using Kill and Killall. Learn how to identify PIDs, free up resources, and close frozen programs without restarting.

I agree to receive announcements of interest about this Blog.

Andrés Cruz

ES En español