Greenwebpage Community Blog Tutorials How to Kill a Process Using Kill Command in Linux
Tutorials

How to Kill a Process Using Kill Command in Linux

The “kill” command in the Linux system is used to kill unwanted processes. Terminating unresponsive system processes helps to maintain your system’s stability and performance. You can either gently terminate the process or forcefully kill it.

This technical post will illustrate how to use the “kill” command to terminate processes in Linux, particularly on the Ubuntu 24.04 system.

How to Kill a Process Using Kill Command in Linux?

The following commands will demonstrate the main uses of the “kill” command in Linux systems.

View the System’s Processes via “top”

In Linux systems, such as Ubuntu 24.04, the “top” command is convenient to identify and inspect the system’s processes that need to be killed or terminated:

top

In response to the above command, you will see a list of running processes on your system. You can identify the particular process that needs to be terminated.

Kill the Process Using ID

For example, if you want to forcefully terminate “firefox”, you can simply use the “-9”, which is the code of the SIGKILL signal:

kill -9 13762

This command will immediately kill the particular process on your Ubuntu 24.04 system.

Inspect the system’s Process through “ps”

The “ps” command with the “aux” option is used for listing all running processes with detailed information:

ps aux

As you can see above, the command lists all the running processes of your Linux-based Ubuntu system.

You can identify the processes from the list to terminate them using the terminal.

Kill a Process using the ID

Here, you will see how to use the “kill” command to terminate or kill the process by its Process ID, such as “5197”:

kill 5197

Without using any additional option will kill the process normally.

If the above command does not work to kill the process, then use the “-9” option, which is used to kill the process forcefully:

kill -9 5197

You can also specify the “-SIGKILL” instead of its code number (i.e. -9):

kill -SIGKILL 5197

Both the above command is used for the same purpose, thus either you use the option code (i.e. -9) or the option name (i.e. -SIGKILL).

Kill Multiple Processes

You can kill more than one process with one command. Let’s see how it works:

Identify the multiple process IDs (PIDs) in the running process list.

Now, use the “kill” command followed by these PIDs and execute the command:

kill 6529 6533 6542

This will kill the selected or identified PID on your system.

You can verify these processes using the same command:

kill 6529 6533 6542

You will see the message “No such process” after successfully executing the command.

Kill a Process by Process Name

In case you don’t want to use the PID, you can utilize the process name to kill the process using the following command:

pkill firefox

The empty output confirms that the process (i.e., firefox) has been killed or terminated successfully.

The “kill” command enables you to use the “-f” option to match against the entire/full command line, not just the process name:

pkill -f firefox

When this command runs it will search for the full command line rather than only the process name to kill.

View All Available Signals

To view all the available signals and utilize them according to your needs, run the following command:

kill -l

You can use the option number or name with the “kill” command to enhance the command’s functionality.

Conclusion

In Linux systems, including Ubuntu 24.04, you can terminate or kill unresponsive or unwanted processes very simply. You can use the “top” or “ps aux” command from your terminal to identify the unwanted processes. To terminate the process, simply use the syntax “kill <option> Process ID or Name”.

Exit mobile version