Skip to content

Latest commit

 

History

History
123 lines (80 loc) · 2.85 KB

kill.md

File metadata and controls

123 lines (80 loc) · 2.85 KB

kill

The kill command is used to send signals to processes, typically to terminate them. While the default action is to terminate a process, kill can send various signals to control process behavior.

Basic Usage

  • Syntax:

    kill [options] [PID...]
  • Examples:

    kill 1234
    • Sends the default SIGTERM signal to terminate the process with PID 1234.
    kill -9 1234
    • Sends the SIGKILL signal to forcefully terminate the process with PID 1234.

Common Signals

  • SIGTERM (15):

    • The default signal sent by kill. It requests the process to terminate gracefully, allowing it to clean up resources.
    kill 1234
    • Gracefully terminates the process with PID 1234.
  • SIGKILL (9):

    • Forcefully terminates a process immediately without allowing it to clean up. This is a last resort when a process won't respond to SIGTERM.
    kill -9 1234
    • Immediately kills the process with PID 1234.
  • SIGHUP (1):

    • Often used to reload a process's configuration files without terminating it.
    kill -HUP 1234
    • Sends a hangup signal to the process with PID 1234, usually causing it to reload its configuration.
  • SIGSTOP (19):

    • Pauses a process without terminating it. The process can be resumed later with SIGCONT.
    kill -STOP 1234
    • Stops the process with PID 1234.
  • SIGCONT (18):

    • Resumes a paused process that was stopped with SIGSTOP.
    kill -CONT 1234
    • Resumes the process with PID 1234.
  • SIGUSR1 and SIGUSR2:

    • User-defined signals that can be programmed to perform specific actions.
    kill -USR1 1234
    • Sends SIGUSR1 to the process with PID 1234.

Usage Tips

  • Finding the PID:

    • Use ps, top, or pgrep to find the process ID (PID) before using kill.
    ps aux | grep process_name
    • Finds the PID for process_name.
  • Terminating Multiple Processes:

    • You can send a signal to multiple processes by listing multiple PIDs.
    kill 1234 5678 9101
    • Sends SIGTERM to PIDs 1234, 5678, and 9101.
  • Sending a Signal by Name:

    • You can specify signals by their name instead of the number.
    kill -HUP 1234
    • Sends SIGHUP to PID 1234.
  • Forcefully Killing a Process:

    • Use kill -9 as a last resort to terminate an unresponsive process.
    kill -9 1234
    • Forcefully kills PID 1234.

Summary

The kill command is a versatile tool for managing processes in Linux. It allows users to terminate, pause, resume, or send custom signals to processes. While kill is often associated with terminating processes, it can be used for a variety of process control tasks, making it an essential tool for system administration and process management.