Sobes.tech
Middle

How to kill a process in Linux? With which commands?

sobes.tech AI

Answer from AI

In Linux, a process can be killed using several commands:

  • kill <PID> — sends the SIGTERM signal (default), which requests a graceful termination.
  • kill -9 <PID> — sends the SIGKILL signal, which forcefully terminates the process without allowing it to handle the signal.
  • pkill <process_name> — kills processes by name.
  • killall <process_name> — kills all processes with the specified name.

Example:

kill 1234        # send SIGTERM to process with PID 1234
kill -9 1234     # forcefully kill the process
pkill nginx      # kill all nginx processes
killall firefox  # kill all firefox processes

It is important to first try a gentle termination (kill without -9) so that the process can properly release resources.