kill – kill a process or send signal in Unix
kill command is used for stopping a process in Unix. It’s also capable of sending a specific signal to a process, allowing it to complete with variable levels of gracefulness.
Stop a Unix process with kill
The simplest form of using kill command needs a process ID. You’re also usually specifying a signal ID (specific action of kill command) – most common is signal 9 (SIGKILL).
Let’s start a sleep process for 60 seconds and make it run in background:
Perfect! 26756 is the process ID, let’s double-check that:
Excellent, that’s the one! Let’s kill this process then:
Press Enter one more time after typing the command, and you should see the confrimation that process is killed:
Signals You Can Send with kill Command
There’s quite a few ways to notify a Unix process that you want it to terminate. Although most commonly we’re using kill -9 and kill -15, there are a few more really useful signals that you should know about. We’ll use in place of a numeric process ID that will be specific to your needs.
[Most Useful kill signals in Unix][kill-signals]
- SIGHUP (kill -1)
- SIGINT (kill -2)
- SIGQUIT (kill -3)
- SIGKILL (kill -9)
- SIGUSR1 (kill -10)
- SIGTERM (kill -15)
Read more here: [Most Useful Process Signals for Kill Command][kill-signals].
Killing other users’ processes
Killing other users’ processes is allowed only when you’re running as root. If you attempt killing someone else’s process, you’ll get an error.
Let’s see if we can find some processes belonging to other users, not my username greys.
Excellent! Process 26799 is running as root, should be good enough for our experiment!
we’re running as my user id, just to be clear. Let’s double-check with id command:
…this means that I wouldn’t be able to kill process 26799 because it’s running under user root:
See also
kill command is used for stopping a process in Unix. It’s also capable of sending a specific signal to a process, allowing it to complete with variable levels of gracefulness.
Stop a Unix process with kill
The simplest form of using kill command needs a process ID. You’re also usually specifying a signal ID (specific action of kill command) – most common is signal 9 (SIGKILL).
Let’s start a sleep process for 60 seconds and make it run in background:
Perfect! 26756 is the process ID, let’s double-check that:
Excellent, that’s the one! Let’s kill this process then:
Press Enter one more time after typing the command, and you should see the confrimation that process is killed:
Signals You Can Send with kill Command
There’s quite a few ways to notify a Unix process that you want it to terminate. Although most commonly we’re using kill -9 and kill -15, there are a few more really useful signals that you should know about. We’ll use
[Most Useful kill signals in Unix][kill-signals]
- SIGHUP (kill -1)
- SIGINT (kill -2)
- SIGQUIT (kill -3)
- SIGKILL (kill -9)
- SIGUSR1 (kill -10)
- SIGTERM (kill -15)
Read more here: [Most Useful Process Signals for Kill Command][kill-signals].
Killing other users’ processes
Killing other users’ processes is allowed only when you’re running as root. If you attempt killing someone else’s process, you’ll get an error.
Let’s see if we can find some processes belonging to other users, not my username greys.
Excellent! Process 26799 is running as root, should be good enough for our experiment!
we’re running as my user id, just to be clear. Let’s double-check with id command:
…this means that I wouldn’t be able to kill process 26799 because it’s running under user root: