Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!rice!rice!sun-spots-request From: Mark_Weiser.PARC@xerox.com Newsgroups: comp.sys.sun Subject: Re: Child control with the Notifier Keywords: Miscellaneous Message-ID: <1990Nov1.000701.23753@rice.edu> Date: 1 Nov 90 00:23:23 GMT Sender: sun-spots-request@rice.edu Organization: Sun-Spots Lines: 50 Approved: Sun-Spots@rice.edu Originator: spots@titan.rice.edu X-Sun-Spots-Digest: Volume 9, Issue 355, message 1 X-Original-Date: Wed, 10 Oct 1990 11:21:22 PDT X-Refs: Original: v9n317 The problem is that you have to give control back to the notifier so that it can do the wait for you and reap the children. As long as you are in your loop the notifier cannot do anything. This is a very common problem, and the solution I use is to, rather than loop, schedule myself to run again ASAP and return to the notifier, keeping track of the iterations with a global variable. This problem came up so often that I wrote the following simple routines to make it easier to schedule an arbitrary procedure call in the future: /* * Call procedure f in a little while. */ struct call_wrapper { /* Dynamically allocating a wrapper ensures unique notifier id's. */ void (*f)(); } do_with_delay(f, secs, usecs) void (*f)(); int secs, usecs; { Notify_value do_the_call(); struct call_wrapper *w; struct itimerval timer; /* Sigh, so much work just to wait a bit before starting up. */ timer.it_interval.tv_usec = 0; timer.it_interval.tv_sec = 0; timer.it_value.tv_usec = usecs; timer.it_value.tv_sec = secs; w = (struct call_wrapper *)calloc(sizeof(struct call_wrapper), 1); w->f = f; notify_set_itimer_func(w, do_the_call, ITIMER_REAL, &timer, NULL); } /* * Wrapper to make sure procedures from do_with_delay return good values * to the notifier. */ Notify_value do_the_call(w, which) struct call_wrapper *w; { (*(w->f))(); free(w); return NOTIFY_DONE; }