How can I kill a running process in Linux using the kill command?
Published on Aug. 22, 2023, 12:20 p.m.
To kill a running process in Linux using the kill command, you need to follow these steps:
- Identify the process ID (PID) of the running process that you want to kill. You can do this by using the
ps
command, which will show you a list of running processes along with their PID number. - Once you have identified the PID of the process you want to kill, you can use the
kill
command followed by the PID to terminate the process. For example, to kill a process with PID 1234, you would use the following command:
kill 1234
- If the process does not respond to the
kill
command, you can use thekill -9
command followed by the PID to force the process to terminate. For example:
kill -9 1234
Note that the kill
command sends a signal to the process, asking it to terminate gracefully. If the process does not respond to the signal, the -9
option can be used to force it to terminate immediately.
To kill multiple processes at once in Linux, you can use the pkill
command. The pkill
command allows you to search for processes based on their name or other attributes and terminate them. Here is an example of how to use the pkill
command to terminate all processes that match a certain name:
pkill process_name
This command will terminate all processes whose name matches “process_name”. You can also use additional options with the pkill
command to specify how to match the processes, for example, by specifying a user or a signal to send.
Alternatively, you can use the killall
command to terminate all processes that match a certain name. The killall
command works similar to pkill
, but the syntax is different:
killall process_name
This command will also terminate all processes whose name matches “process_name”.