foreground, background — execute two commands, sequentially or in parallel
foreground
[--separator alt-sep
] {left-prog
} {;} {right-prog
}
background
[--separator alt-sep
] {left-prog
} {&} {right-prog
}
foreground and background are chain-loading utilities that run left-prog
as a child process created by fork(3) and chain load to right-prog
in the current process.
Both are executed as if with the execvp(3) function.
left-prog
and right-prog
may contain their own command line options, which foreground and background will ignore.
The [--separator] command line option specifies an alternative separator argument, to scan for in place of {;} or {&}.
foreground waits for the child process to finish before continuing in the parent, executing the programs sequentially. background runs child and parent in parallel, without waiting.
The primary use of foreground and background is from a nosh(1) script to enact command lists. When invoking foreground or background from within a shell script, remember that {;} or {&} must be escaped or quoted in order to prevent the shell from recognizing it.
The commands look for the leftmost instance of the separator {;}/ {&}, and separate left from right there.
Further instances of the separator in right-prog
are left alone.
This allows longer lists, by using another foreground or background in right-prog
. However, these commands are intended only for enacting simple sequential or parallel command lists.
For more complex command lists, these are not the correct tools.