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 the 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 the Linux process is perhaps the most popular way using ps command like below.

List Process

List Process

We provide aux parameters to get all processes with the required information about each process. In the screenshot, we can see only some of the process which is sorted by their PID or process id. PID is important because we will kill processes 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 the process named watch with grep.

LEARN MORE  Windows Task Manager Tutorial

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 the PID of watch process to kill it.

Kill Process

Kill Process

After we list the 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 are 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 processes in the system.

LEARN MORE  Best Linux Distros of 2019

Kill All Process For Current User

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

Kill All Process For Current User

Kill All Process For Current User

We have killed all processes related to 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 PIDs to the kill command. This will kill all the provided processes. In the example, we select two processes those PIDs 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 *