Want to learn how to deal with an unresponsive process on Linux? The kill and pkill commands are there to help you out.
Dealing with unresponsive programs can be a tricky job, especially if you’re running on older hardware. In that case, system freezing becomes a common issue. Luckily, there are plenty of ways to kill unresponsive processes in Linux.
The kill and pkill commands provide simple yet effective solutions to terminate unresponsive zombie processes from the terminal. The below sections describe how to kill hung processes in Linux using kill and pkill.
Terminate Unresponsive Processes Using kill
The kill command in Linux allows you to quit unresponsive processes at ease. It sends a terminating signal to the process. By default, kill sends the SIGTERM signal, represented by signal number 15. The following example uses kill to stop a process having a PID of 27065.
Users can send other signals by specifying the signal name or number. For example, the below kill commands stop a zombie process using the SIGKILL system signal, represented by signal number 9.
kill -9 27065
kill -SIGKILL 27065
The difference between SIGTERM and SIGKILL is that processes can catch and ignore the SIGTERM signal. But, SIGKILL is immune to process handling and kills programs immediately.
You can view a list of all available signals using the below kill commands.
Overall, SIGKILL will be more suitable when dealing with unresponsive system processes. On the other hand, SIGTERM is the way to go if you want to terminate hung programs gracefully.
Kill Unresponsive Processes Using pkill
The pkill command makes terminating processes in Linux easier by allowing us to kill programs based on their name. For example, the below command kills the nano program using pkill.
Like kill, pkill also sends the SIGTERM signal by default. Use the SIGKILL signal if you want to stop the unresponsive process immediately.
pkill -9 nano
How to Get the Process ID (PID) of a Process
Having the PID information can be a huge help when terminating unresponsive processes in Linux. You can get the PID number of a process in several ways. The following command retrieves the PID of a process named nano using the grep command and ps.
ps aux | grep nano
You can also use the pgrep command, which spits out the process ID directly.
Managing Unresponsive Process on Linux
The kill and pkill commands make dealing with unresponsive processes in Linux effortless. All you need to stop a zombie process is its PID and access to a shell. However, you may need additional sudo permissions when killing processes belonging to another user. So, if you’re on a multi-user system, ask the administrator to add you to the sudoers list before you take any action.
Want to grant administrative privileges to a Linux user? Here’s how you can add a user to the sudoers list.
About The Author