Processes In Linux
In Linux, a process is a running instance of a program. When you execute a program, it becomes a process, an independent, executing entity with its own memory space. Each process is assigned a unique identifier, the Process ID (PID). Processes are fundamental to the functioning of the operating system and play a crucial role in multitasking, allowing the computer to execute multiple tasks concurrently.
We can use multiple commands to list the running processes in Linux like ps, top, htop, and atop commands in Linux.
ps
provides a snapshot of processes. (ps full form is process status)top
andhtop
offer real-time monitoring.atop
gives detailed insights.pgrep
finds processes based on criteria.
ps -ef is the most commonly used command if you are using ps for listing processes .
here -e is for Lists all processes on the entire system, offering a complete overview of running tasks and programs.
and -f is for Displays the hierarchy of processes in a visual ASCII art format, illustrating parent-child relationships.
Kill Command
kill command in Linux (located in /bin/kill), is a built-in command which is used to terminate processes manually. kill command sends a signal to a process that terminates the process. If the user doesn’t specify any signal that is to be sent along with the kill command, then a default TERM signal is sent that terminates the process.
syntax : kill [signal] PID
Signal can be specifed in 3 different ways : by number or by sig prefix or without sig prefix.
The table below shows some common signals and their corresponding numbers.
| Signal Name | Signal Number | Description | | --- | --- | --- | | SIGHUP | 1 | It hangup detected on controlling terminals or death of controlling process. | | SIGINT | 2 | It interrupts from keyboard. | | SIGKILL | 9 | It kills signal. | | SIGTERM | 15 | It terminates signal. |
To check signal name and number we can use
kill -l
command.By default, the
kill
command sends the SIGTERM signal, allowing the process to perform cleanup operations before termination. If the process doesn’t respond to SIGTERM or if immediate termination is required, you can use the SIGKILL signal with the-9
option:It’s important to note that forcefully terminating a process with SIGKILL may result in data loss or corruption, so it’s recommended to try SIGTERM first and resort to SIGKILL only if necessary.
How to kill multiple processes at the same time ?
Answer : kill 1234 4321 2342
How to kill all the processes with the name "firefox" ?
Answer : killall firefox