Raspberry Pi

5 Methods to Stop a Program Running on Raspberry Pi

The performance of your Raspberry Pi system highly depends on the number of processes running in the background. Those processes that are frozen or unused are consuming excess memory and CPU resources. The only solution to improve the performance of your system is to stop those processes so that you can continue working with your projects on Raspberry Pi.

In this article, you will find different ways to stop programs on Raspberry Pi to control excess memory consumption.

How to Stop a Program Running on Raspberry Pi

The Raspberry Pi system doesn’t have enough power to handle the excess load; thus, you may experience slow performance due to a high number of running processes in the background. To stop these processes from running, there are different approaches to tackle them, which are given below:

  1. Stop a Program Through Process ID
  2. Stop a Program Using its Name
  3. Stop a Program Using CTRL+C
  4. Stop a Program from a Task Manager
  5. Stop a Program Through systemctl Command

1: Stop a Program Through Process ID

The simplest way to stop a program running on Raspberry Pi is by killing a process with its ID using the “kill” command. However, first, you will need to find the process ID and you can do so by running the following command:

$ ps aux

The above command lists the number of processes running in the background and to kill any process, you will need to use the process ID using the following command:

$ sudo kill -9 <process_ID>

The above terminal output will forcefully kill the process with an ID “856” by sending a level 9 signal, which is powerful enough to stop the running process.

2: Stop a Program Using its Name

You can also stop or kill a process using its name in the command-line terminal and to do this method, you will need to run the following command first to get the ID of the processes run by a single program:

$ sudo ps aux | grep -i <program_name>

We are stopping ssh daemon:

$ sudo ps aux | grep -i sshd

From the above terminal command, you will see the list of processes run by a program called “sshd” and from this list, you can use the process ID with kill command to stop the process.

$ sudo kill -9 <process_ID>

3: Stop a Program Using CTRL+C

The Raspberry Pi users most commonly utilize this method to stop a program from running on your Raspberry Pi device. This is the easiest approach to do as it will stop the running process from your terminal using the “CTRL+C” key. To find out how this process works, let’s run a simple program “vlc” on the terminal.

Now, use the “CTRL+C” keys in the terminal to stop the program on your Raspberry Pi device.

4: Stop a Program from a Task Manager

Like other systems, you can also stop a program running on your Raspberry Pi device through Task Manager as well. To do this method, open the Task Manager on your Raspberry Pi device from the “Accessories” section in the main menu.

At the Task Manager, you will see the list of processes running on your system and to kill any process, right-click on it and select the “kill” option to stop the process.

Click on the “Yes” option to Stop the process or a program on Raspberry Pi.

5: Stop a Service on Raspberry Pi Through systemctl Command

The systemctl command is another useful program utility that allows the Raspberry Pi users to stop the services of a program running on your Raspberry Pi device. This type of command is mostly utilized on web services like Apache, MySQL and more. If any service is running on your Raspberry Pi device, you can stop it through the following command:

$ sudo systemctl stop <service_name>

You must replace the “service_name” with the service you want to stop. In our case, we are stopping the Apache service on Raspberry Pi.

$ sudo systemctl stop apache2

The above command will stop the service, but if it doesn’t work, you can use the kill command to stop the service. However, you first need to kill the service through a low-level signal so that it saves the important information before exiting.

$ sudo systemctl kill -s 2 apache2

In case if you are not doing any important task with this service, you can stop it with a high-level signal “9”.

Conclusion

Stopping a frozen or unused program on Raspberry Pi can be pretty much helpful in speeding up your device performance as it will reduce memory and CPU consumption. The five simplest methods are discussed in the above guidelines to stop a program on your device. In all methods, as mentioned earlier, you must need to kill the process or service of a program on your Raspberry Pi device by forcefully stopping it through the kill command.

About the author

Awais Khan

I'm an Engineer and an academic researcher by profession. My interest for Raspberry Pi, embedded systems and blogging has brought me here to share my knowledge with others.