One of the interesting features that make Linux operating systems to be different from other operating system is the fact that the operating system comes with a kill command. Have you ever wondered why Linux servers have a high run-time?. This is because most of Linux packages can be installed, updated or upgraded without having to restart the entire server. This is a massive blow to other operating systems as this feature makes Linux dominate in the market place with over 90% of servers in the world running on Linux.
In a clear context on how the kill command comes into play, we all have encountered a frozen application in our commonly used windows operating system, and we will have this pop-up that says to “End Process,” and when you click, it closes the entire application. That’s the kill command in windows.
Luckily for us all, Linux integrated the operating system with a kill command that allows us to kill processes that disturb the functionality of the system.
In this article, you will be learning a lot on kill commands with various signals passed and how it is used to kill processes and as well as how it can be used to log a remote user out from the system.
THE SYSTEM KILL SIGNALS
The kill, killall and pkill can send a signal to processes on the system. signals can be specified either by name or by number. Users can kill their processes but are not permitted to kill other users' processes by default except with root privileges. When the kill, pkill or the killall command are issued without any signal, it will send -15 (-TERM) signal.
The commonly used signals are;
Signal number 1 –HUP: Is used to restart a process
Signal number 9 –KILL: Is used to kill a process. It is fatal and cannot be blocked or handled
Signal number 15 –TERM: It is used to terminate a program. Unlike the kill command, it can be blocked or handled. It politely ends a process and allows self-clean up
Signal number 18 –CONT: It causes a program to resume if stopped
You can view all available signals on the Linux system by entering the command kill –l or killall –l on the terminal
These are available signals that can be used to kill a process. Please note that signal numbers vary on the different Linux hardware platform. However, it still retains its name and its meaning. It is advised to use the signal names instead of numbers.
HOW TO KILL A PROCESS
They are various ways in which one can kill a process. You can send signal explicitly from the keyboard. By pressing ctrl+c kills a process, ctrl+z suspends a process, ctrl+\ dumps a process.
We will b focusing on the kill, killall and pkill command to kill processes in the system
HOW TO USE KILL COMMAND TO KILL PROCESSES
The kill command sends a signal to kill processes by its process ID. The kill command has various signals that are passed to it. However, you have to know the process ID of the process you want to kill by entering the top command. This will view all available processes and their PID.
The syntax goes as follows;
We just initiated a SIGKILL signal to a process using the kill command
HOW TO USE PKILLL AND KILLALL COMMAND TO KILL PROCESSES
The killall and the pkill command are used to send a signal to one or more processes matching the same criteria; it kills processes by name rather than with their PID.
We just killed a running firefox program using pkill and killall command. They are so many options when using the killall command. You can see all available options by entering the killall command on the command line. You can also view all available pkill command by using the man pkill command on the terminal. All of these options can’t be discussed here. Lookup more of these commands from the options provided
HOW TO LOG REMOTE USERS OUT ADMINISTRATIVELY
A remotely logged in user can be logged out from a system when the user is consuming lots of the system resources or when the user violates the security of the system or simply for administrative needs.
When need comes, the user is expected to close all available session, quit all unused application to free up the resources. However, in a case when the user can not be contacted, the system administrator has every right to log out the user administratively using signals to protect the security of the system.
This is another important aspect of signals in Linux. To view a remotely logged in user, use the w command
To terminate all processes of one user, use the pkill command
pkill –u henry
To kill all users processes and login shells use the SIGKILL signal.
pkill –SIGKILL –u henry
Now you can kill processes and as well terminate user’s sessions and processes
Please if need be to add to this article you can drop a message in the comment