For long running processes, rather than blocking your prompt, it’s often useful to push commands to the background and complete other tasks.
To run a command in the background.
nohup you can run a command which will continue after logout. It will ignore SIGHUP signals.
nice sets a lower priority.
screen you can run a command which can be resumed after logout. It creates a new window with multiple processes instead of multiple Unix login sessions, so it is resource efficient.
List all background processes
To send currently running command to background, first stop the process,
To bring a background process to the foreground
fg fg %1
To destroy a background process
kill %1 kill -9 %1 kill <pid>
To receive an email notification when a background process finishes
<command> | tee command.log | mailx -s 'PROCESS COMPLETE' email@example.com &
To run a set of jobs when cpu levels permit, use batch. ctrl+d to end input.
firstname.lastname@example.org > ~/.forward batch -m command1 command2 command3
You can list batch jobs and kill using the id
at -l at -r id