Killing process on a port, with a single command without fuser -k
Killing the process
It happens regularly that when you stop the process(in my case mostly a node server or flask server) and restart in the same terminal session. It gives the error saying
PORT is still in use
. In that case, using ps aux
and grep
, you find the process id, and kill it. In this stackoverflow answer by Hamid Tavakoli.
This simple one line does it for you
kill -9 $(ps aux | grep '\snode\s' | awk '{print $2}')
the above serves as an example for killing an node js process, which is still utilizing the port. It depicts the powerful use of piping. the \s
on both sides of node is for whitespaces and $2
fetches the pid using awk.