For example, check whether the 4200 port number is occupied.
Enter the command
sudo lsof -i: 4200 in the terminal .
If the port is occupied, the PID value will appear, otherwise there will be no
sudo lsof -i:4200
appears after pressing enter:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
ng\x20ser 26462 root 23u IPv4 6676157 0t0 TCP localhost:4200 (LISTEN)
ng\x20ser 26462 root 28u IPv4 6680806 0t0 TCP localhost:4200->localhost:60652 (FIN_WAIT2)
ng\x20ser 26462 root 30u IPv4 6786256 0t0 TCP localhost:4200->localhost:42774 (ESTABLISHED)
electron 26572 root 110u IPv4 6784563 0t0 TCP localhost:42774->localhost:4200 (ESTABLISHED)
node 26731 root 124u IPv4 6680805 0t0 TCP localhost:60652->localhost:4200 (CLOSE_WAIT)
Then kill the process and enter the command
sudo kill 26462
Explain that 26462 is the PID value that appears above sudo lsof -i:4200