In this article, we would see how to kill a process in Ubuntu. Usually, we think of instructing the process to end with the help of kill command-line utility. But, there is more to it. With kill, we can even make a process stop its functioning and then instruct it to continue as and when required.
But, before that we need to identify the Process ID (PID) of a process. This can be easily identified through ps or top command. Use any of the following –
Kill a process in Ubuntu
Once we have identified the PID, we can issue the following in terminal to kill the process –
kill -15 <PID>
kill -SIGTERM <PID>
At this stage, you may wonder why we have used -15 & –SIGTERM in the second and third command. Actually, all the three commands would yield the same result. The default signal to kill is SIGTERM (Terminate signal). And, its signal number is 15. There are other signals as well. We will discuss those as we move ahead in the article.
So, sometimes even the SIGTERM can’t kill a process. Then, we have got an more powerful alternative i.e. SIGKILL (Kill signal). Its signal number is 9. To use SIGKILL –
kill -9 <PID>
SIGTERM kills the process gracefully, But, SIGKILL would end it abruptly.
SIGSTOP & SIGCONT in kill
Moving on to how to stop and continue a process. We can use SIGSTOP and SIGCONT to stop and continue a process. To stop a process –
kill -SIGSTOP <PID>
Now, run top command again, and see the status of the process. It is denoted with S column/header. You would find T there. It means the process has been stopped by a control signal.
To continue the process again, use –
kill -SIGCONT <PID>
Run top command again to see the status. It changes to its default status now.
In conclusion, we have discussed how to kill a process in Ubuntu distribution.