How to Kill a Process in Linux from Command Line
How to Kill a Process in Linux from Command Line
com/kb/how-to-kill-a-process-in-linux
If a Linux process becomes unresponsive or consumes excessive resources, killing it may be the only solution. Most
processes have their own methods of shutting down. Unfortunately, processes can malfunction and require running a
command to manually kill them.
This guide demonstrates how to kill a Linux process using the command line.
Prerequisites
• A system running Linux.
• A user account with root privileges.
• Access to the terminal.
ps [options] Copy
The pidof command is used to find the ID of a process using the process name.
top Copy
The top command interactive mode starts, shows the process IDs, the users, the amount of memory and CPU power
each process uses, the running time, etc.
In addition to killing processes based on name, the killall command can also be used to kill based on the age of the
process. Use the following commands:
• -o. Use this flag with a duration to kill all processes that have been running for more than that amount of time.
• -y. Use this flag with a duration to kill all processes that have been running for less than that amount of time.
The killall -o 15m command kills all processes that are older than 15 minutes, while the killall -y 15m command kills
all processes that have been active for less than 15 minutes.
pkill Command
The pkill command is similar to the pgrep command, in that it kills a process based on the process name, in addition
to other qualifying factors. By default, pkill sends the SIGTERM signal. The syntax is:
kill Command
The kill command terminates processes via the process ID. The syntax is:
The kill command kills a single process at a time with the given process ID. It sends a SIGTERM signal instructing a
process to stop. It waits for the program to run its shutdown routine.
The -signal option can be used to specify a signal other than SIGTERM.
kill -9 Linux Command
https://phoenixnap.com/kb/how-to-kill-a-process-in-linux
kill -9 is used to shut down an unresponsive service. Run it similarly to the regular kill command:
Or:
The kill -9 command sends a SIGKILL signal to a service, shutting it down immediately. An unresponsive program
ignores a kill command, but it shuts down whenever a kill -9 command is issued. Use this command with caution since
it bypasses the standard shutdown routine, and any unsaved data will be lost.
xkill command
The xkill command is a special command that closes a given server's connection to clients. The syntax of the xkill
command is:
If a server has opened some unwanted processes, xkill aborts these processes.
If xkill is run without specifying a resource, then an interface opens up to let the user select a window to close. For
example:
top Command
The top command provides an interface through which a user can navigate the currently running processes. To start
the interface, run the command:
top Copy
To kill a specific process, press k when in the interface, and enter the PID of the process to terminate:
Note: Learn how to use the nohup command to block the SIGHUP signal and allow processes to
complete even after logging out from the terminal/shell.
Conclusion
This guide explained several ways to kill processes in Linux. It is critical to learn and understand these Linux
termination commands for system management and administration.
Next, check out our comprehensive article on Linux network commands, or take a sneak peek at our ultimate list of
Linux commands.