You
might have noticed that, when you launch a program, it takes over the
terminal, preventing you from doing other work in that terminal. This is
because most programs run in the foreground when invoked from the
shell.
If you have a program that takes a long time to complete you might want to run that program in the background. To do that, simply append an ampersand (“&“) after the command. For example, we might want to run the dd command which can take a lot of time. If we run the command as a foreground process we won’t be able to enter any more commands in our terminal window. However, we could run the dd command as a background process:

The dd program will run in the background. We can use the terminal window to enter other commands.
What if a program is run as a foreground process and we want to use the terminal for something else? Well, we can suspend that program. To stop a running program and put it in the background, press Ctrl+Z. To run that program again in the foreground type fg:

In the picture above you can see that we started the dd command as a foreground process. We then suspended the program by pressing Ctrl+Z. We now can enter new commands in the terminal windows. To return the dd command to the foreground we simply type fg.
If you have a program that takes a long time to complete you might want to run that program in the background. To do that, simply append an ampersand (“&“) after the command. For example, we might want to run the dd command which can take a lot of time. If we run the command as a foreground process we won’t be able to enter any more commands in our terminal window. However, we could run the dd command as a background process:

The dd program will run in the background. We can use the terminal window to enter other commands.
What if a program is run as a foreground process and we want to use the terminal for something else? Well, we can suspend that program. To stop a running program and put it in the background, press Ctrl+Z. To run that program again in the foreground type fg:

In the picture above you can see that we started the dd command as a foreground process. We then suspended the program by pressing Ctrl+Z. We now can enter new commands in the terminal windows. To return the dd command to the foreground we simply type fg.
NOTE – we could also type bg instead of fg. bg restores a job to running status, but in the background, so we can use the terminal to enter new commands.
Post a Comment