Here are the steps:
First, try this (replace PID with the number you copied above):
Now, test if it's closed by connecting to the port (replace portNumber with the actual port number):
nc localhost portNumber
If it returns immediately with no output, the port isn't open. However, if it returns some input, try to kill it with:
kill -9 PID
Again, try to connect. If it's still running, try this:
sudo kill -9 PID
Here are the steps for Windows:
netstat -ano | findstr :portNumber
Copy the PID number for the next step.
First, try this (replace typeyourPIDhere with the number you copied above):
taskkill /PID typeyourPIDhere /F
Run the first command again to see if it's closed.
Here are the steps for Linux (courtesy of mayankjoshi)
kill pid kills the process by process id
killall pname kills the process by name
-9 for forceful killing in both kill and killall
sudo if it's a root process.