Introduction to Linux pkill
In the Linux operating system, the pkill is used to kill the current or running process on the environment. As per the specific criteria, the pkill command-line utility sends the single to the running process. In pkill command, we the process can de define in various ways like the full name of the process, from which user the process will run (user name), partial process name, other attributes, etc.
In initially level, the pkill command was written for the Solaris 7 operating system. It was written in 1998. The pkill command-line utility allows trying to use the extended regular expression patterns. The pkill command-line utility was written by Kjetil Torgrim Homme.
Syntax of pkill Command:
pkill [options] pattern
- pkill: We can use the “pkill” keyword in the syntax or command. It will take different arguments like option and pattern. As per the provided arguments, it will send the singles to the running process in the environment and do the necessary actions on it.
- options: We can provide the different flags as the option that is compatible with the “pkill” command.
- pattern: With the help of extended regular expressions or language, we can create the pattern and use it in the same pkill command.
How does Linux pkill Command work?
In the Linux operating system, we are having multiple options to kill the running process. The pkill command is one of them. The pkill command will work on the two different arguments like options and patterns. We can provide different options that are compatible with the “pkill” command. For example, in patterns, we can use the extended regular expression in it. As per the inputs, the pkill command will kill the running process in the environment.
Below are the lists of options that are compatible with the pkill command.
|1||-<sig>, –signal <sig>||It is used to send the signal in terms of the number of the name.|
|2||-e, –echo||It is used to display what is killed.|
|3||-c, –count||It will help to count the matching processes.|
|4||-f, –full||It is used to match the full process name.|
|5||-g, –pgroup<PGID,…>||It is used to match the list of processes with the help of group IDs.|
|6||-G, –group <GID,…>||It will help to match with the real group IDs.|
|7||-n, –newest||It is used to identify or select the most recently started.|
|8||-o, –oldest||It is used to identify or select the last or old process.|
|9||-P, –parent <PPID,…>||It will help to match only the child processes of the given parent name.|
|10||-s, –session <SID,…>||It will help to match the session IDs.|
|11||-t, –terminal <tty,…>||It will help to match by controlling the terminal.|
|12||-u, –euid<ID,…>||It will help to match by effective IDs.|
|13||-U, –uid<ID,…>||It will help to match by real IDs.|
|14||-x, –exact||It will help to match exactly with the command name.|
|15||-F, –pidfile<file>||It is used to read PIDs from the input file.|
|16||-L, –logpidfile||It will fail if the PID file is not locked.|
|17||-h, –help||It will print the help information of pkill command and exit.|
|18||-V, –version||It will display the version information of pkill command and exit.|
Examples of Linux pkill
Given below are the examples of Linux pkill:
pkill Command – Gracefully Stop.
In the pkill command, we have multiple options to kill or stop any process in the Linux environment. As per the requirement, we can gracefully stop the running processes. For stopping the process gracefully, we need to use the “15” number with pkill command.
pkill -15 docker
- As per the above command, we are using the integer value “15” for the graceful-stop of the docker process. Therefore, it will stop all the docker running processes from the environment.
pkill Command – With Full Argument List.
In the pkill command, it is accepting the process name only. But with the help of the “-f” option, it will consider the complete argument list.
pkill -9 -f "ping google.com"
- We have identified the ping command is in a running state. Therefore, with the help of the command name, we can kill the “ping” process.
pkill Command – Kill Process Running with Specific User.
In the pkill command, we have the functionality to kill the running process that are running with the specific user name.
pkill -9 -u test
- In the above pkill command, we are killing the processes that are initiated by the different users, i.e., “test” users.
- In the second screenshot, we are killing the ping command but with the pattern name “test” (user name). Once we kill the process with the user name “test user,” all the running processes will kill those initiated by the “test” user.
pkill Command – Kill the Process.
In the Linux environment, we have the functionality to kill the running process. Therefore, we need to use the integer value “9” with the pkill command.
pkill -9 ssh
- As per the above command, we are directly killing the “ssh” service. Therefore, it will directly kill all the running processes of “ssh.”
We have seen the uncut concept of “Linux pkill Command” with the proper example, explanation, and command with different outputs. The pkill command will send the singles to the running process and help to kill the process with specific patterns. It is important to pgrep the running services then only kill the necessary services with the help of pkill command.
This is a guide to Linux pkill. Here we discuss the introduction, how the Linux pkill command works? And examples respectively. You may also have a look at the following articles to learn more –