Linux tip for DevOps💡: how to quickly kill any process by it’s PID number.

Andrey Byhalenko
DevOps Manuals and Technical Notes
3 min readJan 15, 2024

Using this simple tip, you can kill any running process easily.

Photo by Gabriel Heinzer on Unsplash

Let’s run a sample process first, then execute the top command to display Linux processes in real time.

yes > /dev/null &
top

As you see, the PID of the yes process is 1302. In order to kill it when you are in top view, press k. You will be prompted for a PID and then the signal to send. Type 1302 and press <Enter> twice.

The default signal, as reflected in the prompt, is SIGTERM. However, you can send any signal via number or name.

press k, type the PID number and press <Enter>
press <Enter> (default SIGTERM signal)
yes process is killed

If you wish to abort the kill process, do one of the following, depending on your progress:
1) at the pid prompt, type an invalid number
2) at the signal prompt, type 0 (or any invalid signal)
3) at any prompt, press <Esc>

If you cannot find your process in the output of the top command, you can search for it. Press L, type the process name, and press <Enter>.

To move to the next result, press &.

Another method is to run top -i. This option starts top with the last remembered `i’ state reversed. When this toggle is Off, tasks that have not used any CPU since the last update will not be displayed.

Another way to quickly kill the process is to use the pgrep command (lookup for process based on name):

pgrep yes
kill -9 1582

If you liked my articles, join my newsletter, and you will receive weekly DevOps tutorials, articles, and tips every Saturday.

As a bonus, you will receive a free step-by-step DevOps CI/CD project, which you can use in your portfolio.

Subscribe here: https://junior-devops-hub.ck.page

--

--

Andrey Byhalenko
DevOps Manuals and Technical Notes

I'm a DevOps Engineer, Photography Enthusiast, and Traveler. I write articles aimed at junior DevOps engineers and those aspiring to become DevOps engineers.