Kill a Process

Abhay Jain
2 min readDec 22, 2020

--

If you want to kill a process using the command line, that can be performed by simple steps performed below.

STEP 1: Finding the PID

Case 1: Terminate the process of a particular program

Command: ps aux | grep “[n]ginx”

In the CMD, we have run a command which displays the process running with its PID (i.e. 12514 and 13262).

Decoding the command:

ps: Process Status

a: Show processes for all users
u: Display the process’s user/owner
x: Also show processes not attached to a terminal

grep: Globally search for a regular expression and print matching lines

Value in between the “….” is the name of the process you want to find.

Case 2: Clear a particular port

Command: sudo lsof -i :8080

In the CMD, we have run a command which displays the process running with its PID (i.e. 12514 and 13262).

Decoding the command:

sudo(superuser do): Allows programs to be executed as a root user

lsof: list open files

-i: interactive

After which you mention the port number(:8000).

STEP 2: Killing the Process

Command: sudo kill -9 12514

Decoding the command:

sudo(superuser do): Allows programs to be executed as a root user

kill -9: Terminates the process.

After which you write the PID(a number which shows after the username), which you want to terminate.

--

--

Abhay Jain

Developer with 3 yrs of industrial experience in developing scalable web applications.