https://linuxize.com/post/how-to-kill-a-process-in-linux
Have you ever faced the situation where you launched an application and suddenly while you are using the application it becomes unresponsive and unexpectedly crashes. You try to start the application again, but nothing happens because the original application process never truly shut down completely.
Well it has happened to all of us at some point, hasn’t it? The solution is to terminate or kill the application process. But how?
Luckily, there are several utilities in linux that allows us to the kill errant processes.
In this tutorial we will show you how to use
Regular users can kill their own processes, but not those that belong to other users, while the root user can kill all processes.
The most commonly used signals are:
The steps outlined below will work on all Linux distributions.
Let’s say our Firefox browser has become unresponsive and we need to kill the Firefox process. To find the process PID we can use the pidof command:
The command above will print all Firefox processes:
Once we know the Firefox processes PIDs we can kill all of them with:
Using the same scenario as before, we can kill the Firefox process by typing:
The
killall command accepts several options such as specifying processes
running as user, using regular expresion and killing processes younger
or older than specified time. You can get a list of all options by
typing
For example if we want to terminate all processes running as a user
Have you ever faced the situation where you launched an application and suddenly while you are using the application it becomes unresponsive and unexpectedly crashes. You try to start the application again, but nothing happens because the original application process never truly shut down completely.
Well it has happened to all of us at some point, hasn’t it? The solution is to terminate or kill the application process. But how?
Luckily, there are several utilities in linux that allows us to the kill errant processes.
In this tutorial we will show you how to use
kill
and killall
utilities to terminate a process in Linux. The main difference between
these two tools is that killall terminates running processes based on
name, while the kill terminates processes based on Process ID number
(PID).Regular users can kill their own processes, but not those that belong to other users, while the root user can kill all processes.
kill
and killall
can send a specified signal to a specified processes or process groups. When used without a signal both tools will send -15
(-TERM).The most commonly used signals are:
1
(-HUP): to restart a process.9
(-KILL): to kill a process.15
(-TERM): to gracefully stop a process.
- using number (e.g., -1)
- with the “SIG” prefix (e.g., -SIGHUP)
- without the “SIG” prefix (e.g., -HUP).
-l
option to list all available signals:kill -l # or killall -l
Advertisement
Killing processes with the kill command
In order to terminate a process with the kill command, first we need to find the process PID. We can do this through several different commands such astop
, ps
, pidof
and pgrep
.Let’s say our Firefox browser has become unresponsive and we need to kill the Firefox process. To find the process PID we can use the pidof command:
pidof firefox
2551 2514 1963 1856 1771
kill -9 2551 2514 1963 1856 1771
Killing processes with the killall command
The killall command terminates all programs that match a specified name.Using the same scenario as before, we can kill the Firefox process by typing:
killall -9 firefox
killall
(without any arguments).For example if we want to terminate all processes running as a user
sara
we would run the following command:killall -u sara
No comments:
Post a Comment