How can I run a shell script and immediately background it, however keep the ability to inspect its output any time by tailing /tmp/output.txt
It would be nice if I can foreground the process too later.
PS It would be really cool if you can also show me how to "send" the backgrounded process in to a gnu screen that may or may not have been initialized.
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
If you have already started the process in the foreground, but you want to move it to the background, you can do the following:
bg
command to resume the process, but have it run in the background instead of the foreground.