To 'background' a process when you start it
Simply add an ampersand (&
) after the command.
If the program writes to standard out, it will still write to your console / terminal.
To foreground the process
Simply use the fg
command. You can see a list of jobs in the background with jobs
.
For example:
sh -c 'sleep 3 && echo I just woke up' & jobs
To background a currently running process
If you have already started the process in the foreground, but you want to move it to the background, you can do the following:
- Press Ctrl+z to put the current process to sleep and return to your shell. This process will be paused until you send it another signal.
- Run the
bg
command to resume the process, but have it run in the background instead of the foreground.
bg
command ..." ) – Ebberta