# Cheat Sheet #day66 - kill

### `kill` Command Cheatsheet

The `kill` command in Unix-like systems is used to terminate processes by sending signals to them. It allows users to manage and control processes running on the system. Here’s a quick reference guide:

#### Basic Syntax

```sh
kill [OPTIONS] PID...
```

#### Common Signals

* `-1`, `SIGHUP`: Hangup signal. Typically used to instruct a process to reload its configuration.
    
* `-2`, `SIGINT`: Interrupt signal. This is typically generated by pressing Ctrl+C and is used to terminate a process gracefully.
    
* `-9`, `SIGKILL`: Kill signal. Forces termination of a process. It cannot be caught or ignored by the process.
    
* `-15`, `SIGTERM`: Termination signal. This is a general-purpose signal to terminate a process gracefully.
    

#### Examples

1. **Terminate a process by PID (default signal is** `SIGTERM`):
    
    ```sh
    kill 1234
    ```
    
2. **Send a specific signal to a process (e.g.,** `SIGKILL`):
    
    ```sh
    kill -9 1234
    ```
    
3. **Send a** `SIGHUP` signal to reload a process (e.g., a daemon):
    
    ```sh
    kill -1 1234
    ```
    
4. **Terminate multiple processes by PIDs:**
    
    ```sh
    kill 1234 5678 9101
    ```
    
5. **Send a** `SIGINT` signal to terminate a process gracefully (e.g., Ctrl+C):
    
    ```sh
    kill -2 1234
    ```
    

#### Additional Options

* `-l`, `--list`: List available signals. Use with `kill -l`.
    
    ```sh
    kill -l
    ```
    
* `-s SIGNAL`, `--signal=SIGNAL`: Specify a signal by name or number.
    
    ```sh
    kill -s SIGTERM 1234
    ```
    
* `-p`, `--pid PID`: Specify the process ID.
    
    ```sh
    kill -9 --pid 1234
    ```
    

#### Tips

* **Graceful Termination:** Use `SIGTERM` (`-15`) for normal termination as it allows the process to clean up resources.
    
* **Forceful Termination:** If a process does not respond to `SIGTERM`, use `SIGKILL` (`-9`) to force termination, but this can leave resources in an inconsistent state.
    

#### Additional Information

* **Help option:**
    
    ```sh
    kill --help
    ```
    
* **View manual page for** `kill`:
    
    ```sh
    man kill
    ```
    

The `kill` command provides essential functionality for managing processes in Unix-like systems, allowing users to terminate processes gracefully or forcefully depending on the situation. For more detailed information and advanced usage, refer to the `man` page or use `kill --help`.
