in reply to Re: SIGCHLD and sleep()
in thread SIGCHLD and sleep()

Thanks, I was making the process of maintaining the actual time slept versus how much time had elapsed during a particular iteration of the loop entirely too complicated. The simple loop does ensure the daemon sleeps for the correct amount of time.

However, this does leave defunct processes sitting in the process table until the daemon interates again and I reap the processes. Which I can live with, but ideally I'd like to know if it is possible to avoid.

Is there a way to create a thread to handle the signals immediately and store the exit statuses in a shared hash? I don't know if I should be mixing ithreads and forking to begin with, but that would be the perfect solution to my problems.

Thanks again,
overbyte

Replies are listed 'Best First'.
Re^3: SIGCHLD and sleep()
by dave_the_m (Monsignor) on Aug 09, 2005 at 20:19 UTC
    You should be able to the reaping in a SIGCHLD handler, which upon exit, returns you to the sleep loop. Or include the reaping within the timing loop, eg
    while (1) { while (remaining) { sleep(remaining); while (($pid = wait) != -1) { ... do reaping stuff } } ... check for new jobs and spawn them ... }

    Dave.

      Thanks again for your help. This is actually what I ended up doing (reaping within the timing loop), and was just returning to post about. It seems to work well, without cluttering the process table with defunct processes. It would've only been ~1 min before they got reaped, but it's still ugly to see those zombies in the process table.

      overbyte