In this article, we will talk about what a process is in the Linux background and how to run it. The instructions are extremely simple and clear.
Linux has 2 modes of working with processes:
foreground (priority, foreground) – a mode in which the launch of a new command is possible only after the completion of the previous one;
background (background, background) – to launch a new command, you do not need to complete the previous one.
Working in the background mode is convenient because you can work with several teams in parallel. The terminal window is always available in order to enter new commands into it. It remains to figure out how to work with this competently.
To run the background command (in the background), you need to enter its name and add an empersand & to the end of the line. It is indicated after a space. Eg:
thisisyourcommand argument1 argument2 &
For example, we need to start unpacking the tar archive. To do this, we use the Linux command:
$ tar -xf archive.tar &
[1] 3459
$
You can use the terminal to enter new commands into it and continue working while the archive is unpacked in the background.
As you work, you can see the numbers [1] 3459. Let's figure out what it is and what it is used for.
[1] is the number assigned to the process by the shell.
3459 is the ID of the created process (PID).
If you can run the process in the Linux background, then you can get it from there. To get the process out of the background, you need the fg command. If you enter it without specifying the task number, the system will default to the last running process from the background.
To output a specific task from the Linux background, you need the command:
fg [1]
In this example, we have removed the first command from the background. You need to specify a specific number.
It also supports the ability to view those tasks that are currently being worked out in the background. You need to enter the command
$ jobs
Now you know how to start a Linux background process (in the background), view its status and change the priority.