Linux Kill Process Tutorial With Examples

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-kill-process-tutorial-with-examples/
PINTEREST
PINTEREST
INSTAGRAM

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

List Process

To kill process we need to get information about 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 are 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 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 process. Now we will filter process according to their names or parameters. In this example we will use 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.

Kill Process

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

LEARN MORE  Dstat- Monitor Linux Server Performance

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

Now we provide PID of watch process to kill it.

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

Process Signal

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

Kill Process Forcibly

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

OR

OR

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

Process Owner

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

Kill All Process For Current User

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

LEARN MORE  How To Secure Linux From Automated Attacks?

We have kill all process related 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 provided processes. In the example we select two process those PID’s are 1903 and 1948  and than 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

 

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-kill-process-tutorial-with-examples/
PINTEREST
PINTEREST
INSTAGRAM

You may also like...

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)