how to stop running port in ubuntu

C++
sudo kill -9 `sudo lsof -t -i:3002`sudo kill -9 `sudo lsof -t -i:{PORT_NUMBER}`
Source

Also in C++: