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:
[greys@redhat8 ~]$ sleep 60 &
[1] 26756
Perfect! 26756 is the process ID, let’s double-check that:
Excellent, that’s the one! Let’s kill this process then:
[greys@redhat8 ~]$ kill -9 26756
Press Enter one more time after typing the command, and you should see the confrimation that process is killed:
[1]+ Killed sleep 60
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.
I'm a principal consultant with Tech Stack Solutions. I help with cloud architectrure, AWS deployments and automated management of Unix/Linux infrastructure. Get in touch!