Running python as a deamon (rfork)

Donn Cave donn at u.washington.edu
Fri Oct 15 12:34:19 EDT 1999


Quoth Greg Ewing <greg.ewing at compaq.com>:
| henk_p at my-deja.com wrote:
|> 
|> If I log out, I want the process to continue, so in some way it has to
|> detach itself from the shell parent process.
|
| Exiting of the parent process won't cause the child to die;
| it will be inherited by the init process. (On BSD-influenced
| unices, anyway - I'm not sure about pure SysV derivatives.)

I think he's looking out for a terminal driver issue.  The terminal
driver works with terminal driver process groups, and when it gets
a disconnect it arranges for a SIGHUP to be delivered to process groups
currently associated with that terminal.  Hence the mania for cutting
a daemon loose from its ``controlling terminal'', via obscure and
not too portable ioctls (specifically TIOCNOTTY, issued to the current
controlling terminal device, '/dev/tty'.)

Sometimes a shell will get into the act and deliver SIGHUP signals
to its background jobs on logout.  Hence the common practice
of a fork() where the parent exits right away and the child continues,
losing the background job.

It's also common practice to close all open file descriptors, prior
to the TIOCNOTTY step.  That may be essential for the TIOCNOTTY, but
probably is just resource deallocation lest some inode or device be
kept around indefinitely because the daemon happened to inherit it.
Of course Stevens' book on UNIX programming is going to cover these
matters in much more authoritative way, I probably have half of it wrong.

	Donn Cave, University Computing Services, University of Washington
	donn at u.washington.edu




More information about the Python-list mailing list