Notifications
Clear all

Linux kill process


admin
Posts: 74
Admin
Topic starter
(@admin)
Member
Joined: 11 months ago

How to Kill a Process in Linux?(Linux kill process tutorial)

Topic Tags
1 Reply
Alaikha
Posts: 48
(@alaikha)
Eminent Member
Joined: 11 months ago

Kill a Process in Linux

How to Kill A Process in Linux using Command Lines - TechOwns

How Do You Kill Processes in Linux?

Linux processes that become unresponsive or consume a lot of resources may need to be killed. All processes have their own methods of shutting down. On occasion, processes can malfunction and not shut down properly. When a background process is unresponsive, a command must be used to terminate it. Be sure to consider permissions before terminating or killing a process.

All processes can be terminated by a root user. Adding sudo before a command will run it as root, or you can obtain a root shell using su. Once that's done, run the command. The process that is being killed will receive a termination message. 

Among the different types of termination messages are:

  • SIGKILL

The SIGKILL command is the ultimate method of terminating a process. A process is always killed abruptly, generating a fatal error. Normally, SIGKILL always works. If it does not, there is something wrong with the operating system.

  • SIGTERM

It attempts to terminate a process, but unlike SIGKILL, it could be blocked or handled in some other way. In this way, a process can be terminated in a more gentle manner. 

When it comes to most purposes, SIGKILL will be the quickest and most efficient way to terminate the process.

1: View Linux processes in progress

Get a complete overview of the currently running processes with the top command. In addition to the process IDs and users, the top command will reveal how much memory and CPU power each process is using. Press k and enter the process ID directly into the top interface to kill processes. Press q to exit the top interface.

Top command kill process in Linux

 2: Identify the process to be killed

Using the ps command, locate a process

Similar to top, ps will display similar information, but without an interface. Rather than a list of your running processes, ps lists them in the order you specify.

ps <options>

ps aux kill process in linux

A common option to add to this is "-aux":

  • -a : Displays processes of all users, rather than only that of the current user.
  • -u : Displays detailed information regarding each process.
  • -x : Include processes that are not controlled by users, but by daemons.

3: Execute the Kill command in order to terminate the process

In Linux, you can kill a process through several methods, depending on the process name, the process pid, or just how long the process has been running.

  • killall Command

Processes can be killed by name using the killall command. It will send out a SIGTERM signal by default. You can use killall to eliminate multiple processes at once.

  • pkill Command

Pkill is similar to pgrep in that it will kill a process based on its name as well as other qualifying factors. SIGTERM is sent by default by pkill.

  • kill Command

When the kill command is used, it will kill one process at a time according to the given process ID. A SIGTERM signal will be sent to the process indicating that it must stop. The program will then run its shutdown routine.

  • kill -9 Linux Command

Using kill -9 to terminate an unresponsive process is a useful technique. It is carried out similarly to a regular kill command.

  • top Command

A user can navigate through currently running processes using the top command.

  • xkill command

A special type of command, xkill, closes the connection between a server and its clients.

Reply