If I run a program with an infinite loop with nohup
, will the program run indefinitely (until the machine is reset or until I manually terminate it)?
2 Answers
Nohup sets the default behavior of the HANGUP signal, which might get overriden by the application. Other signals from other processes with permission (root or same user) or bad behavior (seg faults, bus errors) can also cause program termination. Resource limitations (ulimit) can also end the program.
Barring these, your infinite loop might well run a very long time.
Following are the two important line from nohup's source code.
(void)signal(SIGHUP, SIG_IGN);
// Ignore SIGHUP
execvp(*argv, argv);
// Run the command.
So until your application calls something like
signal (SIGHUP, SIG_DFL);
//OR some custom signal handler
In the normal circumstances it will continue to run until you restart machine or kill it yourself.
It might also be terminated in the cases pointed by kmarsh.