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.
Let's start a sleep process for 60 seconds and make it run in background:
[greys@redhat8 ~]$ sleep 60 &  26756
Perfect! 26756 is the process ID, let's double-check that:
[greys@redhat8 ~]$ ps -aef | grep 26756 greys 26756 26344 0 19:27 pts/0 00:00:00 sleep 60 greys 26758 26344 0 19:27 pts/0 00:00:00 grep --color=auto 26756
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:
+ Killed sleep 60
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.
[greys@redhat8 ~]$ ps -aef ... root 26799 797 0 19:32 ? 00:00:00 sleep 60 greys 26800 26344 0 19:32 pts/0 00:00:00 ps -aef
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:
[greys@redhat8 ~]$ id uid=1000(greys) gid=1000(greys) groups=1000(greys),10(wheel)
…this means that I wouldn't be able to kill process 26799 because it's running under user root:
[greys@redhat8 ~]$ kill -9 26799 -bash: kill: (26799) - Operation not permitted