Linux - Start, manage and stop processes ?

Father

Professional
Messages
2,601
Reaction score
836
Points
113
A process is responsible at the operating system level for the execution of a program or command. This sounds like a rather trivial task, but since a lot of programs and background services run in parallel, it is not so easy to distribute the computing time between all programs fairly or sensibly.

Programs and commands
A program or command is actually just an executable file. So a program file differs from other files by the fact that the exceute bit x is set.

Only by starting an as it were lifeless program file it becomes a living process, which is managed by the Linux kernel.

*.exe files
From time to time the question arises, where are the *.exe files under Linux. Until a few years ago the correct answer was: There are no *.exe files. Executable programs are identified by the access bit x, the file identifier *.exe known from Windows is thus superfluous.

Meanwhile, this answer is no longer quite correct in that there may indeed be isolated *.exe files under Linux. These are programs that have been developed in the C# programming language and that rely on the Mono library for execution. The Mono library is in turn an open source implementation of Microsoft's .NET framework.

Start programs

Program start under X
In graphics mode, you usually start programs via a menu or by clicking on an icon. Desktop systems like KDE, Gnome or Unity offer an additional way to start programs quickly with the shortcuts ALT+F2 or WIN.

Text console, terminal window
Alternatively, you can also start programs in a terminal window or in a text console. Just type the name of the program and press Tab. Especially Linux professionals often choose this way, because it is faster to type a few letters than to search for the program in branched menus.

Usually it is enough to simply specify the name of the program. The shell interpreter then searches for the program in all directories specified in the PATH environment variable. The following lines show a typical setting of this variable :

Code:
┌──(carder㉿father)-[~]
└─$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/snap/bin

If you want to start a program that is not located in any of these directories, you must specify the full path. This also applies to programs in the current directory! Here the path is simply given by a dot, so for example ./father

-----

Foreground and background processes
When you start programs in the Start menu of your desktop, they naturally run as so-called background processes, i.e. without interfering with each other. You can start additional programs without having to wait for the previously started programs to finish.

The behavior is completely different when you run a program in a text console or terminal. The program is started as a foreground process. Before you can enter the next command in the terminal, you have to wait for the end of the last started program.

But you can also start programs in the background in text consoles or terminal windows. To do this, simply enter the & character at the end of the command:
Code:
┌──(carder㉿father)-[~]
└─$ firefox &
[1] 39653

If you & forgot, you can also convert the program to a background afterwards. Interrupt the program execution with CTRL + Z and continue the program with bg:
Code:
┌──(carder㉿father)-[~]
└─$ chromium
[40086:40086:0622/212516.189123:ERROR:gpu_init.cc(426)] Passthrough is not supported, GL is desktop
[40086:40086:0622/212516.285230:ERROR:sandbox_linux.cc(374)] InitializeSandbox() called with multiple threads in process gpu-process.
^Z
[1]+  Stopped                 chromium

┌──(carder㉿father)-[~]
└─$ bg
[1]+ chromium &

If you use the fg command instead of bg, the program will continue as a foreground process.

With some commands, various text outputs interfere with background execution. However, you can easily suppress these by redirecting to /dev/null. For example, the following command sets up a file system in the background:
Code:
root# mkfs.ext4 /dev/sdc1 > /dev/null &
 
Top