In any operating system, we will need to work with processes. In fact, we do it every time a command is executed. Furthermore, we do it just by running a terminal or connecting via ssh.
Managing processes, that is, checking which processes are running, launching processes in the background, or terminating them, is a common task that you will have to get used to in order to take advantage of your Raspberry Pi.
In this post, we will see how to manage processes in a Linux system like Raspbian on Raspberry Pi.
To run a command, simply type the name of the command,
If instead of a command we want to run an executable file in the current folder, we would do the following.
#run application in current folder
Where it is necessary for the executable file to have execution permissions.
If during the execution of a command or application we want to cancel its execution, we press the key combination,
control + c
Manage background processes
When we run a command or application in the console, it remains blocked until the command finishes. If we want the execution to take place in the background, we add the ’&’ key like this
#start process in background
If we want to put a command that is already running in the background, we can use the key combination.
#put processes in background
control + z
If we want to view the processes running in the background, we use the command
#show processes in background
And if we want to bring back the most recently put background process, we use,
#bring process to foreground
Show running processes
Another very common need is to know which processes are currently running on the machine. For this, we have several available commands.
To show the active processes in the system, we use the command
#show active processes
ps: Shows the processes that are currently active in the system.
If instead, we want to display all processes running in the system, we can do
#show all processes
The previous commands display the processes in a list. Instead, we can display in a similar way to ‘ps -ef’ with a blocking command that continuously displays the processes with the following command,
#show all processes
top: Shows all running processes.
Finally, the previous command has a visually more attractive version that we can run with,
Finally, sometimes we will need to terminate a running process. To do this, we use the command
#close a process
Where ‘PID’ is the process identifier that we can obtain with the ‘ps’ command.
Some processes need to use a “forced close” to be terminated. We can do this by adding the ‘-9’ parameter
#force close process by PID
kill -9 PID
If we want to terminate a process by its name, we can use the ‘killall’ command, which will terminate all processes with the same name.
#terminate process by name
killall -9 name
That’s it! With these few commands, we can manage processes on any Linux-based operating system like Raspbian on our Raspberry Pi.