↑ ↓ select, Enter open, Esc close

Terminate a process and force kill only if needed

Caution: This command changes the system. Understand what it does before you run it.

Adjust the values, the command updates live
root@server
kill 1234; sleep 5; kill -0 1234 2>/dev/null && kill -9 1234

Sends the normal termination signal first, so the process can clean up, close files and finish transactions. After five seconds, kill -0 checks whether it still exists, and only then follows kill -9, which terminates immediately without cleanup. Root is only needed for other users’ processes.

Note: Check the PID beforehand with ps -fp <PID>. Never stop database servers like MariaDB with kill -9, use systemctl stop instead.

Also searched as

  • kill hung process
  • how to use kill -9 properly
  • process will not terminate
  • force kill a stuck process

Related one-liners

All in Processes

Read first, then run.

The commands on myline.de act directly on servers, files and databases. A wrong path or placeholder can delete data irreversibly or make a server unreachable.

  • All commands are provided without warranty and are not tested on every system.
  • Understand what a command does before running it, and check every placeholder.
  • Make a backup first and, if possible, try it on a test system.
  • You run commands at your own risk. Liability for damages is excluded to the extent permitted by law.