Terminate a process and force kill only if needed
kill hung process | how to use kill -9 properly | process will not terminate | force kill a stuck process | kill | signal | hung-processCaution: This command changes the system. Understand what it does before you run it.
kill 1234; sleep 5; kill -0 1234 2>/dev/null && kill -9 1234Sends 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