Enhancing Skills

kill: Send a signal to a process to terminate it

Command: kill

The kill command sends a signal to a process, typically to terminate it. By default, kill sends the SIGTERM signal, which requests a graceful shutdown of the process. You can also send other signals, such as SIGKILL, which forces an immediate termination.


Sample Commands and Outputs:

  • kill PID: Sends the default SIGTERM signal to terminate the process with the specified PID. Sample Command and Output:
  $ kill 1234

Description:

  • 1234: The PID of the process to terminate.
  • This command requests a graceful shutdown of the process with PID 1234. If the process does not terminate, you may need to use a stronger signal like SIGKILL.
  • kill -9 PID: Sends the SIGKILL signal, forcing an immediate termination of the process. Sample Command and Output:
  $ kill -9 1234

Description:

  • -9: The option to send the SIGKILL signal, which cannot be ignored by the process.
  • 1234: The PID of the process to forcefully terminate.
  • kill -l: Lists all available signals that can be sent with the kill command. Sample Command and Output:
  $ kill -l
  1) SIGHUP  2) SIGINT  3) SIGQUIT  4) SIGILL  5) SIGTRAP  6) SIGABRT  7) SIGBUS
  8) SIGFPE  9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM
  15) SIGTERM 16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP 21) SIGTTIN
  22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ 26) SIGVTALRM 27) SIGPROF 28) SIGWINCH
  29) SIGIO 30) SIGPWR 31) SIGSYS

Description:

  • Lists all signals with their corresponding numbers. For example, SIGTERM (signal 15) is the default termination signal, while SIGKILL (signal 9) forces an immediate shutdown.

Note: The kill command is essential for process management in Linux, allowing users to terminate processes that are no longer needed or that have become unresponsive. Use signals carefully, especially SIGKILL, as it does not allow the process to clean up resources or save data before terminating.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.