DevOps Interview Questions: How to kill a running process. kill, pkill, killall

Hi in this article we will talk about a very easy DevOps interview question. How to kill a running process. Earlier we have talked about VPC designlogging system designmonitoring system designpage fault, etc.

kill, pkill and killall

So we can use kill, pkill and killall commands to kill a process in Linux. All of these commands are wrappers over a kill system call. Kill system call takes process ID and signal to kill the process. Let’s take a look at all three of these commands one by one.

kill:

Kill is very simple just pass a process ID and a signal [options] to kill any process. This directly makes the kill system call and the process is killed.

Syntax: kill -signal pid

killall:

This command takes the process name as an argument to kill the process. Behind the scene, it also calls the kill system call. To get the process ID to pass to the kill system call it will try to traverse and parse the /proc file system to get the processes whose names are matching with the given argument and then it passes their process id to the kill system call.

Syntax: killall -s sginal process_name 

pkill:

pkill can take partial names and patterns in argument to kill a process. It also makes kill system call so need to get the process ID of the process. pkill can take patterns which is very powerful. But as everyone knows, with great power comes great responsibility, it can kill important processes if the pattern passed is wrong.

Syntax: pkill options pattern

If you don’t know about system calls you can learn about them in the below video.

We have not talked about signals in this article, If you want to read more about signals that can be passed to these commands you can look at this video.

In short, all of these commands use the same system call, the difference is in the way they identify the process to kill.

This was a small article on how to kill a process in Linux. If you are preparing for DevOps and SRE Interviews. Don’t forget to give a look at the below playlist

https://www.learnsteps.com/tag/interviewquestions/

If you like the article please share and subscribe.


Gaurav Yadav

Gaurav is cloud infrastructure engineer and a full stack web developer and blogger. Sportsperson by heart and loves football. Scale is something he loves to work for and always keen to learn new tech. Experienced with CI/CD, distributed cloud infrastructure, build systems and lot of SRE Stuff.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Are you preparing for DevOps and SRE Interview?

Here is a book for you.


Interview preparation and interview questions for DevOps and SRE






A good reads for last-minute preparations for handling DevOps and SRE interviews at companies like LinkedIn, Visa, Atlassian, etc.