How to Kill a Process in Linux?

There are several ways to terminate a running process in Linux system:

  1. Pressing the Ctrl + C shortcut: in the terminal, you can press the Ctrl + C shortcut to abort the current running command or program.
  2. To terminate a specific process, you can use the kill command. First, use the ps command to find the process ID (PID) of the process you want to terminate, then use the kill command followed by the corresponding PID to end the process. For example:
  3. List all processes with the name “process_name” and then force kill the process with the specific PID.
  4. Using the pkill command: This command can directly terminate a process based on its name. For example:
  5. Terminate the process named process_name.
  6. By using the killall command, all processes matching a specific name can be terminated. For example:
  7. Terminate all processes with the name ‘process_name’.

It should be noted that when terminating a process using the kill command, different signals can be sent to the process. Commonly used signals include:

  1. 9. Forcefully terminate the process.
  2. Elegantly terminate the process.

Usually, it is recommended to first try sending signal 15 to the process; if the process does not respond, then send signal 9 to forcefully terminate the process.

bannerAds