Kill process running on a port - Linux

As an instance, to kill all the process running on TCP port 8000, use the below command to detect the process id:

sudo lsof -i TCP:8000

And now kill it with its pid:

kill -9 <pid_value>

Certain processes like mysqld and apache2 might restart after you have killed them using the above commands. Even if you use the killall command, they will still appear after some time.

In such cases, I advise you to use application specific commands to stop a service. For example, to kill the Apache process on Ubuntu, use the command:

sudo systemctl stop mysqld

Extra

See a list of Top process that using the most memory or CPU or disk:

top
htop

Search a running process:

ps -ef | grep firefox
pgrep firefox