From a Unix command line, a background process can be launched using the "&" operator. The
bg command can resume a suspended job (sending
SIGCONT), running it in the background. Using the
fg command will also reconnect standard input its parent terminal, bringing it into the foreground. The
jobs command will list all processes associated with the current terminal and can be used to bring background processes into the foreground. When a
login session ends, via explicit logout or network disconnection, all processes, including background processes, will by default be terminated, to prevent them from becoming
orphan processes. Concretely, when the user exits the launching shell process, as part of shutdown it sends a
hangup signal (
SIGHUP) to all its
jobs, to terminate all the processes in the corresponding
process group. To have processes continue to run, one can either not end the session, or end the session without terminating the processes. A
terminal multiplexer can be used to leave a session running but detach a virtual terminal from it, leaving processes running as child processes of the session; the user can then reattach session later. Or, termination can be prevented by either starting the process via the
nohup command (telling the process to ignore SIGHUP), or by subsequently running
disown with the job id, which either removes the job from the job list entirely, or simply prevents SIGHUP from being sent. In the latter case when the session ends, the child processes are not terminated, either because they are not sent SIGHUP or because they ignore it, and thus become orphan processes, which are then adopted by the
init process (the kernel sets the init process as their parent), and they continue running without a session, now called
daemons.
Example In this example running on
Unix, the
sleep utility was launched into the background. Afterward, the
ps tool was run in the foreground, where it output the below text. Both were launched from the shell. PID TT STAT TIME COMMAND 54659 10 S 0:00.06 su (zsh) 54703 10 IN 0:00.00 - sleep 1000 54852 10 R+ 0:00.00 - ps -U botty -axd ==Smartphones==