Methods of payment Abuse

How to start a process in the Linux background

26.01.2023, 23:52

In this article we will tell you what a process in the Linux background is and how to start it. The instructions are very simple and easy to understand.

In Linux there are 2 modes of working with processes:

  • foreground (foreground, foreground) - a mode in which a new command can be started only after the last one is finished;
  • background - you don't need to finish the previous command to start a new one.

What are Linux background commands for?

Working in the background mode is convenient because you can work with several commands in parallel. The terminal window is always available to type new commands into it. It remains to figure out how to work with it properly.

How to launch a background command in Linux: step-by-step instructions

To run a backgroud command (in the background), you need to enter its name and add an empersand sign & to the end of the line. It is specified after a space. For example:

thisisyourcommand argument1 argument2 &

For example, we need to run the unpacking of a tar archive. To do this, we use the command in Linux:

$ tar -xf archive.tar &

[1] 3459

$

You can use the terminal to enter new commands into it and work on it while the archive is being unpacked in the background.

You can see the numbers [1] 3459 as we go along. Let's understand what it is and what it is used for.

[1] is the number assigned to the process by the shell.

3459 is the identifier of the created process (PID).

If you can start a process in the Linux background, you can get it from there. To get a process out of the backgroud, you need the fg command. If you enter it without specifying a job number, the system will by default pull the last running process out of the background.

To remove a specific task from the background in Linux, you need a command:

fg [1]

In this example, we have taken the first command out of the background. You need to specify a specific number. The ability to view the jobs that are currently running in the background is also supported.

You need to enter the command:

$ jobs

Now you know how to run a Linux background process, view its status and change its priority.