when needing to run a mongodb server and another port is running for some weird reason
lsof -i :27017
this displays the pid
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mongod 17381 rosssavill 9u IPv4 0x38d7c23ab2a3b0f7 0t0 TCP localhost:27017 (LISTEN)
to kill the process
kill -9 17381
now if i run
lsof -i :27017
no value is returned which means the process has been killed
the same applies to any port that's running, we just need to know it's port number and apply the steps above
more about how to kill processes online
it actually shows that once you have the pid you can just run the kill command
to fix the stale pid problem to do with postgres follow these instructions