Linux Kill Process Tutorial With Examples – POFTUT

Linux Kill Process Tutorial With Examples

Operating systems are a bed for applications. These applications are executed as processes. Process start, waits, and ends. Through their lifetime their complete given jobs. In this guide, we will look at how to kill Linux process in different ways.

List Process

To kill the process we need to get information about the process like process id, owner, etc. One way to list Linux process is perhaps the most popular way using ps command like below.

List Process

List Process

We provide aux parameters to get all process with required information about each process. In the screenshot, we can see only some of process which is sorted by their PID or process id. PID is important because we will kill process generally according to their PID.

Another useful way to list processes interactively is top command. This command will provide the following screen.  Process ID’s are depicted as PID in the first column of the process list table.

List Process

List Process

Filter Process With Name By Using Grep

We can list all the process. Now we will filter process according to their names or parameters. In this example, we will use a popular Linux tool named grep . We will pipe the result of the command to the grep command to filter for watch string. This will only print the process those have the term watch

List Process Filter Process With Name By Using Grep

Filter Process With Name By Using Grep

We filter process named watch with grep.

LEARN MORE  How To Use Psexec Tools To Run Commands and Get Shell Remote Windows Systems?

Kill Process

Now we can kill the process by providing its PID with kill command provided by Linux. Kill command have following simple syntax.

As we see option part is optional by provides useful operations if needed.

Now we provide PID of watch process to kill it.

Kill Process

Kill Process

After we list watch process we can’t see watch ls process.

Process Signal

Operating system process terminology provides signals which are sent to process like a command. Signals can be killed, pause, interrupt, etc. kill command by default sends a TERM signal to the process. There is alternative signals. We can list these signals provided by the operating system like below.

Process Signal

Process Signal

Kill Process Forcibly

We have sent TERM signal by default with kill command but there is no response or action about the killing process. We can make things more brutal by sending SIGKILL or simply KILL.

OR

OR

Kill Process Forcibly

Kill Process Forcibly

As we see there are different ways to express kill options like -9 or -SIGKILL or -KILL. In the kill example, we see that our watch ls process is killed with option -9 .

Process Owner

As we know for security reasons Linux provides process ownership. Process ownership establishes security and prevents unprivileged users to interact or kill the disowned process. Root user or a user which can get root privileges like sudoer can kill all process in the system.

LEARN MORE  How To Pause and Resume Powershell and Cmd Scripts In Windows With Examples?

Kill All Process For Current User

This is a harsh way to kill all the process we might kill. If we run this command with a regular user it will kill all process related with the user.

Kill All Process For Current User

Kill All Process For Current User

We have killed all processes related with the user and the remote connection is closed naturally.

Kill Multiple Processes

Up to now, we have provided only single PID to the kill command. There is also another usage by providing multiple PID’s to the kill command. This will kill all the provided processes. In the example we select two process those PID’s are 1903 and 1948  and then provide these PIDs to the kill command like below. After the kill command, we check their existence again but there is no process.

Kill Multiple Processes

Kill Multiple Processes

1 Response

  1. 05/08/2018

    […] Linux Kill Process Tutorial With Examples […]

Leave a Reply

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

Enjoy this blog? Please spread the word :)