daemon : not atomic, depends on scheduling options

Stern, Eli eli.stern at intel.com
Tue Nov 15 16:20:44 UTC 2011


Following is a concern that daemon() might fail due to scheduling.

The daemon() function does not synchronize itself, and so it is prone to failure depending on system scheduling.
Example:
- Last line in a script is a process that uses daemon(). Within daemon:
  * parent does fork();
  * Parent gets CPU, child did not start.
  * Parent does _exit();
  * The script recognizes that the last line of the script has been executed, and send a SIGHUP to the pgrp.
  * Child receives SIGHUP and exits.

All this can be avoided if the parent waits on waitpid till the child detaches (setsid()). At this point the parent receives ECHILD on the waitpid, and can exit safely.

Can someone who understands uClibc please confirm or reject?

Thanx

Eli Stern 
---------------------------------------------------------------------
Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.



More information about the uClibc mailing list