# kill — Send Signals to Processes

> Terminate, stop or control processes with signals – kill targets by PID, killall and pkill by name. Covers SIGTERM, SIGKILL and safe usage.

Source: https://www.jpkc.com/db/en/cheatsheets/shell-system/kill/

<!-- PROSE:intro -->
kill is your central tool for sending signals to running processes – to terminate them gracefully, force-kill them, pause them or tell a daemon to reload its configuration. By default `kill` sends the polite SIGTERM (15), which lets a program clean up; `kill -9` (SIGKILL) forces the end with no cleanup and risks data loss, so reach for it only as a last resort. `killall` and `pkill` match by name and can easily hit too many processes, so check first with `pgrep`.
<!-- PROSE:intro:end -->

## kill — By Process ID

`kill <pid>` — Send SIGTERM (graceful termination) to a process by PID.

```bash
kill 1234
```

`kill -9 <pid>` — Send SIGKILL (force kill, cannot be caught or ignored).

```bash
kill -9 1234
```

`kill -SIGTERM <pid>` — Send SIGTERM by name (same as kill without flags).

```bash
kill -SIGTERM 1234
```

`kill -<signal> <pid>` — Send a specific signal by number or name.

```bash
kill -HUP 1234
```

`kill <pid1> <pid2> <pid3>` — Send SIGTERM to multiple processes.

```bash
kill 1234 1235 1236
```

`kill -0 <pid>` — Check if a process exists (signal 0 sends nothing, just checks).

```bash
kill -0 1234 && echo 'Process exists' || echo 'Process gone'
```

`kill -l` — List all available signal names and numbers.

```bash
kill -l
```

## killall — By Process Name

`killall <name>` — Send SIGTERM to all processes matching the exact name.

```bash
killall nginx
```

`killall -9 <name>` — Force kill all processes matching the name.

```bash
killall -9 php-fpm
```

`killall -i <name>` — Interactive mode: ask for confirmation before killing each process.

```bash
killall -i python3
```

`killall -u <user>` — Kill all processes owned by a specific user.

```bash
killall -u testuser
```

`killall -u <user> <name>` — Kill processes by name owned by a specific user.

```bash
killall -u www-data php-fpm
```

`killall -o <time> <name>` — Kill only processes older than the specified time.

```bash
killall -o 1h php-fpm
```

`killall -y <time> <name>` — Kill only processes younger than the specified time.

```bash
killall -y 5m my-script
```

`killall -w <name>` — Wait for all killed processes to die before returning.

```bash
killall -w nginx
```

`killall -r '<regex>'` — Kill processes matching a regular expression.

```bash
killall -r 'worker-[0-9]+'
```

## pkill — By Pattern

`pkill <pattern>` — Send SIGTERM to processes whose name matches the pattern.

```bash
pkill firefox
```

`pkill -9 <pattern>` — Force kill processes matching the pattern.

```bash
pkill -9 chrome
```

`pkill -f '<pattern>'` — Match against the full command line (not just the process name).

```bash
pkill -f 'python3 worker.py'
```

`pkill -u <user>` — Kill all processes owned by a user.

```bash
pkill -u guest
```

`pkill -t <tty>` — Kill all processes on a specific terminal.

```bash
pkill -t pts/3
```

`pkill -P <ppid>` — Kill all child processes of a parent PID.

```bash
pkill -P 1234
```

`pkill -x <name>` — Match the exact process name only (no partial matches).

```bash
pkill -x python3
```

## Finding Process IDs

`pgrep <pattern>` — Find PIDs of processes matching a pattern (companion to pkill).

```bash
pgrep nginx
```

`pgrep -l <pattern>` — Show PIDs and process names.

```bash
pgrep -l php
```

`pgrep -a <pattern>` — Show PIDs and full command lines.

```bash
pgrep -a python
```

`pgrep -f '<pattern>'` — Match against the full command line.

```bash
pgrep -f 'node server.js'
```

`pidof <name>` — Find the PID of a running program by exact name.

```bash
pidof nginx
```

## Important Signals

`SIGTERM (15)` — Graceful termination. The process can catch it and clean up. Default signal.

```bash
kill -TERM 1234   # or just: kill 1234
```

`SIGKILL (9)` — Immediate termination. Cannot be caught, blocked, or ignored. Use as last resort.

```bash
kill -9 1234
```

`SIGHUP (1)` — Hangup. Often used to tell daemons to reload their configuration.

```bash
kill -HUP $(pidof nginx)
```

`SIGSTOP (19)` — Pause a process (cannot be caught). Resume with SIGCONT.

```bash
kill -STOP 1234
```

`SIGCONT (18)` — Resume a stopped/paused process.

```bash
kill -CONT 1234
```

`SIGUSR1 (10) / SIGUSR2 (12)` — User-defined signals. Used by applications for custom actions (e.g., log rotation).

```bash
kill -USR1 $(pidof nginx)
```

`SIGINT (2)` — Interrupt (same as Ctrl+C). Graceful stop for interactive programs.

```bash
kill -INT 1234
```

`SIGQUIT (3)` — Quit with core dump (same as Ctrl+\). For debugging.

```bash
kill -QUIT 1234
```

## Common Patterns

`kill $(pgrep -f '<pattern>')` — Kill processes matching a command-line pattern.

```bash
kill $(pgrep -f 'python3 worker.py')
```

`kill $(cat <pidfile>)` — Kill a process using its PID file.

```bash
kill $(cat /var/run/nginx.pid)
```

`kill -HUP $(pidof <daemon>)` — Reload a daemon's configuration without restarting.

```bash
sudo kill -HUP $(pidof nginx)
```

`ps aux | grep <pattern> | grep -v grep | awk '{print $2}' | xargs kill` — Find and kill processes using a pipeline (classic pattern).

```bash
ps aux | grep 'myapp' | grep -v grep | awk '{print $2}' | xargs kill -9
```

`kill -TERM <pid> && sleep 5 && kill -0 <pid> && kill -9 <pid>` — Graceful kill with fallback: try TERM first, then KILL if still alive.

```bash
kill -TERM 1234; sleep 5; kill -0 1234 2>/dev/null && kill -9 1234
```

`fuser -k <port>/tcp` — Kill the process using a specific TCP port.

```bash
fuser -k 8080/tcp
```

`fuser -k <file>` — Kill all processes using a specific file.

```bash
fuser -k /var/log/app.log
```

<!-- PROSE:outro -->
## Conclusion

With `kill` and its relatives you control processes precisely: for everyday work the default SIGTERM usually does the job, letting a program shut down cleanly – and you can address shell jobs of the current session with `kill %1`. Reach for `kill -9` (SIGKILL) only when a process refuses to respond: it aborts hard, without flushing buffers or releasing locks, which can lead to data loss or corrupted files. Be careful with `killall` and `pkill` – they target by name and may accidentally hit the wrong process or several at once; test the pattern first with `pgrep` or `pkill -i`. For daemons, `kill -HUP` is often the right tool to reload the configuration without a restart.

## Further Reading

- [man7.org: kill(1)](https://man7.org/linux/man-pages/man1/kill.1.html) – the Linux manual page for the kill command
- [Wikipedia: Signal (IPC)](https://en.wikipedia.org/wiki/Signal_(IPC)) – background on Unix signals and their numbers
<!-- PROSE:outro:end -->

## Related Commands

- [ps](https://www.jpkc.com/db/en/cheatsheets/shell-system/ps/) – list running processes and their PIDs
- [top](https://www.jpkc.com/db/en/cheatsheets/shell-system/top/) – monitor processes and resource usage live
- [jobs](https://www.jpkc.com/db/en/cheatsheets/shell-system/jobs/) – list background jobs of the current shell

