I'm studying Redhat Linux 7, topic Monitoring and managing Linux processes in it I understand Processess and its command. But I do not understand "Controlling Jobs" and Running jobs in the background and its practical its background and Foreground processes. Can you explain this term to us?
Most commands issued from an interactive shell run in foreground. That basically means that you must wait for the executed command (or processus ) to stop before doing something else. For long/complex programs or scripts, the alternative is to run them in the background. This means that you can continue to work while the long program executes.
& at the end of a command does this. You can also use ctrl-Z to suspend a foreground command and throw it in the background with the
You can thereafter manage these backgrounds tasks (
jobs command), kill them, etc.
Please note that the background command is not detached from your tty : there may be some cases when a background command waits for user input (see
fg command to bring back a job to foreground). If you end your terminal session (through closing the terminal, logout, shutdown, etc.), background jobs may be also killed (see
nohup for more details).
in simple words,
Every process that you start runs in the foreground. It gets its input from the keyboard and sends its output to the screen.
which list all the files in current directory,
A background process runs without being connected to your keyboard. If the background process requires any keyboard input, it waits.The advantage of running a process in the background is that you can run other commands; you do not have to wait until it completes to start another!
The simplest way to start a background process is to add an ampersand ( &) at the end of the command.
$ls ch*.doc &
some below links will help you
Running a program in the background by adding
& at the end is like running an application minimized in Windows or Mac. And using the
fg command is like restoring it back to the desktop.
In comparison, when you press
ctrl+z while a program is running will suspend its execution. Which means it will be stopped from completing what it is doing and sent to the background.
Furthermore, the programs are tied to your current session so if you exit your terminal all the programs running or suspended in the background will end too.