The Raspberry Pi can run a bit slow sometimes, so you want to see what is hogging the processor.
Use the Task Manager utility, which you’ll find on the Start menu in the System Tools program group (Figure 3-8).
The Task Manager allows you to see at a glance how much CPU and memory are being used. You can also right-click on a process and select the option to kill it from the popup menu.
The graphs at the top of the window display the total CPU usage and memory. The processes are listed below that, and you can see what share of the CPU each is taking.
Discussion
If you prefer to do this type of thing from the command line, use the Linux top command to display very similar data about processor and memory and which processes are using the most resources (Figure 3-9). You can then use the kill command to kill a process. You will need to do this as superuser.
In this case, you can see that the top process is a Python program that uses 97% of CPU. The first column shows its process ID (2447). To kill this process, enter this command:
$ kill 2447 |
It is quite possible to kill some vital operating system process this way, but if you do, powering off your Pi and turning it back on again will restore things to normal.
Sometimes, you may have a process running that is not immediately visible when you use top. If this is the case, you can search all the processes running by using the ps command and piping (Recipe 3.29) the results to the grep command, which will search the results and highlight items of interest.
For example, to find the process ID for our CPU-hogging Python process, we could run the following command:
$ ps -ef | grep “python” pi 2447 2397 99 07:01 pts/0 00:00:02 python speed.py pi 2456 2397 0 07:01 pts/0 00:00:00 grep –color=auto python |
In this case, the process ID for the Python program speed.py is 2447. The second entry in the list is the process for the ps command itself.
A variation on the kill command is the killall command. Use this with caution, as it kills all processes that match its argument. So, for example, the following command will kill all Python programs running on the Raspberry Pi.
$ sudo killall python |
See Also
See also the manpages for top, ps, grep, kill, and killall.
You can view these by typing man followed by the name of the command, as shown here:
$ man top |