nohup

Run a command immune to hangups, runs the given Command with hangup signals (SIGHUP) ignored, so that the command can continue running in the background after you log out.

Syntax
      nohup [Command [Arg]...]         

Run command such that it will ignore hangup signals.

Note that commands can set their own response to hangups, overriding nohup.

Without an argument (allowed in only a shell script), causes the shell to ignore hangups for the remainder of the script. `nohup' does not automatically put the command it runs in the background; you must do that explicitly, by ending the command line with an `&'.

If the output file nohup.out cannot be created in the current directory, the nohup utility uses the directory named by the variable HOME to create the file.

If the standard output is a terminal, the standard output is appended to the file nohup.out in the current directory.
If standard error is a terminal, it is directed to the same place as the standard output.

Exit Status
126 The utility was found but could not be invoked.
127 The utility could not be found or an error occurred in nohup.
Otherwise, the exit status of nohup shall be that of utility.

Examples

bash script that takes any simple command and runs it in the background. Logging output and error output to ~/launch The output files are suffixed with the date and time.

#!/bin/bash
mkdir -p ~/launch
logfilename="${1##*/}_$(date +%F_%H%M%S)"
echo "== LAUNCH $@ ==" > ~/launch/${logfilename}_stdout.log
echo "== LAUNCH $@ ==" > ~/launch/${logfilename}_stderr.log
nohup "$@" >>~/launch/${logfilename}_stdout.log 2>>~/launch/${logfilename}_stderr.log &

“Love is a perky elf dancing a merry little jig and then suddenly he turns on you with a miniature machine gun” ~ Matt Groening

Related macOS commands

chroot - Run a command with a different root directory.
exec - Execute a command.
if - Conditionally perform a command.
nice - Change job scheduling priority.
screen - Multiplex terminal, run remote shells via ssh.
su - Run a command with substitute user and group id.


 
Copyright © 1999-2024 SS64.com
Some rights reserved