niemueller.de::home niemueller.de
Open Software. Open Knowledge.




 

Tim's WebLog


To sleep or not to sleep

Today looked for a problem for about an hour which I thought might be worth sharing. The following (most likely common) scenario was to be implemented: one process wants to start another and be notified if something happens to the child process. The proper way to achieve this is to fork(), then execl() the new program in the child, and have the parent call wait() to check for state changes of children.

Now, in I'd guess likewise common is to start with a test program that incorporates sleep(). Fail! After an hour it turns out that the sleep() call will block the SIGCHLD signal (cf. sleep.c). But it does not unblock the signal afterwards. Since the wait() call depends on SIGCHLD, no event would be received
and wait() would starve.

So either you need to unblock the signal after calling sleep(), or better call usleep() which does not suffer this problem (cf. usleep.c).





Top 5 Pages
Wiki
WebLog
SquidGuard Webmin Module
Network Utilities Webmin Module
Friends' blogs




Palm Software
UniMatrix UniMensa UniSorter
UniChat OHS Mobile Onager


My Bookshelf




Valid XHTML 1.1!

RSS Copyright © 2000-2009 by Tim Niemueller