Dealing with misbehaving processes
Regarding the ps
command, by this point you know how to display processes running on your server, as well as how to narrow down the output by string or resource usage. But what can you actually do with that knowledge? As much as we hate to admit it, sometimes the processes our server runs fail or misbehave and you need to restart them. If a process refuses to close normally, you may need to kill that process. In this section, we introduce the kill
and killall
commands to serve that purpose.
The kill
command accepts a PID as an argument and attempts to close a process gracefully. In a typical workflow where you need to terminate a process that won’t do so on its own, you will first use the ps
command to find the PID of the culprit. Then, knowing the PID, you can attempt to kill
the process. For example, if PID 31258
needed to be killed, you could execute the following:
sudo kill 31258
If all goes well, the process will end. You...