Web development and Tech news Blog site. WEBISFREE.com

HOME > linux

How to stop or kill a process in use in Linux

Last Modified : 06 Mar, 2023 / Created : 06 Mar, 2023
View Count

Let's find out how to stop (kill) currently running processes in Linux.

# Stop Linux process., kill

If multiple processes are running on Linux, they continually consume CPU and memory resources. To stop (kill) an existing process to avoid unnecessary resource waste or to reuse it, how can you do it?

Below, we will learn how to identify currently running processes and stop them in the order listed below.

- Find currently running processes.
- Stop using PID (Process ID)

Now we need to first find the process that is currently being used. If you want to stop an app using Python, you can find the process running under the name of Python as shown below.
ps aux

The process can be viewed using the ps command, and in this case, the aux value has been used as an option.

a // Displays processes for all users
u // Shows who is using the processes
x // Displays a list of all processes

Now, let's search for the process being used with Python. We'll add a pipeline and use grep.
ps aux | grep python

You can now see a list of running python processes. By checking from the left, it shows the user and pid. You need to use this pid to stop (kill) the process.

! Stop the currently active PID in Linux.

Now that we know the PID, let's stop it. Enter it as follows:
kill -9 PID

It's simple. If the PID is 1555, you would input it as follows.
kill -9 1555

It's very simple.

! Using the killall command to stop a process, kill.

There is a simpler way. It is to use the killall command. With this command, you can stop all processes using the process name. That is, to stop the python process, you would enter the command as follows.
killall pyhon

It's very easy. By the way, it is also possible to delete only processes that have been running for a certain amount of time.

killall -o 10m <ProcessName>

As an example, 10m is used after the -o option to represent 10 minutes. You can use h for hours and d for days to specify time.

So far, we have learned how to stop current processes in Linux.

Perhaps you're looking for the following text as well?


[Linux] Checking storage capacity and other information using df


How to use cron in Linux, registering task schedules