Question 3.24: The Raspberry Pi can run a bit slow sometimes, so you want t......

The Raspberry Pi can run a bit slow sometimes, so you want to see what is hogging the processor.

Step-by-Step
The 'Blue Check Mark' means that this solution was answered by an expert.
Learn more on how do we answer questions.

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
3.8
3ز9

Related Answered Questions

Question: 3.34

Verified Answer:

Use the Linux df command: $ df -h Filesystem   ...
Question: 3.33

Verified Answer:

Use the Linux date command. The date and time form...
Question: 3.32

Verified Answer:

Edit the file ~/.bashrc using nano (Recipe 3.6), a...
Question: 3.31

Verified Answer:

Run the program or command in the background using...
Question: 3.30

Verified Answer:

Redirect the output to /dev/null using >. For e...
Question: 3.29

Verified Answer:

Use the pipe command, which is the bar symbol (|) ...
Question: 3.27

Verified Answer:

Use the > command to redirect output that would...
Question: 3.28

Verified Answer:

Use the cat command to concatenate a number of fil...
Question: 3.26

Verified Answer:

Use the lsusb command. This will list all the devi...
Question: 3.25

Verified Answer:

Depending on the file type, you will need to use t...