Dealing With Misbehaving Processes in Ubuntu

If you are used to the Windows system, you would have likely come across a misbehaving application, which can most likely be killed using the Task Manager.

This is similar in GNU/Linux, the only difference is that you have to do it over the terminal, so, how do we deal with misbehaving processes on our GNU/Linux server?

If a process refuses to close normally or misbehaving, you may need to kill the process using the kill or killall commands. To get started with this, you first need to figure out the PID of the process, PID is a number assigned to a given process on your system, while humans can easily reference a process by name (e.g bash), the system knows processes by their ID, so, each program you open is given a different PID.

Go ahead and type the ps command in your console:


I’ll assume the PID 321 is behaving, so, to kill it, I’ll execute:

sudo kill 321

Bam! The process should most likely end now, so, you could check the logs for more information as to why it was misbehaving in the first place, and restart.

The way the kill command works is telling the process to cleanly terminate, if successful the process will free its memory and gracefully shuts down. Gracefully shut down means the process is given time to save its progress (the current works its doing), and the release resources (free its memory), in a simple sentence, it is not forced to stop.

If for some reason you aren’t able to close a process, then you would have to force stop it, this is considered an extreme last resort and should be used with caution.

To force stop a process, you will send signal 9 to the process, this will force-closed the process without giving it any time to save its progress or react at all.

Note: By Default, the kill command sends signal 15, you can learn more about the GNU/Linux signal by consulting the man page: man 7 signal

So, to force-close PID 321, I’ll use:

sudo kill -9 321

This will immediately kill the process without gracefulness, if for some weird reason, the process still manages to stay running, then try to reboot the server.

What if you want to kill a process by name?

Fortunately, you can! By using the killall command, you can kill any process by name, but note that it kills any process it finds with the name you’ve given as an option.

For example, let’s say I want to kill all nano editor:

sudo killall nano

You can also send signal 9 to force stop the process as well:

sudo killall -9 nano

Comment policy: Respectful and beneficial comments are welcome with full open hands. However, all comments are manually moderated and those that doesn't relate with what the passage is saying or offensive comments would be deleted. Thanks for understanding!

Leave a Reply

Your email address will not be published. Required fields are marked *