Killing Port
To kill a port on Mac and Linux:
- Find the process using the port:
lsof -i:<PORT_NUMBER>
- Kill the process with its PID:
kill -9 <PID>
The -9
flag forcefully terminates the process, while omitting it allows the process to terminate gracefully. Use -9
only as a last resort if the process is unresponsive.
Example:
Suppose you want to kill the process using port 3001. First, find the process and its PID:
lsof -i :3001
This will be the output:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 70648 anup 24u IPv4 0xc0b4578b035212a7 0t0 TCP *:redwood-broker (LISTEN)
To kill the process with PID 70648 forcefully:
kill -9 70648
Please remember to replace <PORT_NUMBER>
and <PID>
in the commands with the actual port number and process ID you want to work with.