If you are here for the quick answer to how to kill a process in Linux, the answer is fairly simple. First, get the process ID of the process you want to terminate. Second, use the kill command to kill that process. Example assuming your process id is 1234:
Sometimes the kill command isn’t able to take out a process because there are other things depending on it. If you don’t care about those things and want to end the process anyway, use the -9 option. So, the command will look like this:
kill -9 1234
If you want to know more, read on for more detail on the PS command and the KILL command.
What’s the PS command?
If you are running Linux, you may be familiar with the the
ps command, which stands for ‘process status’ is used to display information about running processes.
There are several options you can use to get different outputs:
ps: list the processes running in the current shell for the current user.
ps -e: list all the processes currently running on the system.
ps -ef: list all processes currently running on the system with even more info.
ps -u username: list all processes for a specific user.
ps -aux: list all processes for all 0users along with additional information such as CPU usage, start time, and more.
How to kill a process in Linux
You can kill a process using the
kill command followed by the process ID (PID). Here’s how you do it:
First, find the PID of the process. You can do this using the
ps command. For example, if the process name is “abc”, you can find its PID using:
tekopolis@ubuntu:~$ ps | grep abc
49129 pts/1 00:00:00 abc
Once you have the PID, use the
kill command to terminate the process:
tekopolis@ubuntu:~$ kill PID
Replace “PID” with the actual process ID.
If you don’t have permissions to kill the process it should throw an error. You can use sudo if you have the credentials to do it. If a normal
kill doesn’t work, you can use
kill -9 PID, which sends the SIGKILL signal and should terminate the process. However, use this with caution as it doesn’t give the process a chance to cleanly shut down.
Disclaimer: As with any Linux command that has the potential to break stuff, take care not to mess this up. Consider this the disclaimer that tekopolis isn’t at fault for your usage of this info. We recommend practicing and using this command in a lab/sandbox environment where there is no impact to production environments or revenue generating systems.