DrWhy has asked for the wisdom of the Perl Monks concerning the following question:

We're working on a home-grown search engine daemon here and are having some trouble with signal handling (under 5.6.1, and 5.8.x). We have two processes: the actual search daemon and a watcher. The watcher will automatically restart the search engine under various circumstances, e.g. when the search database has had sufficiently significant changes made to it, or when the search engine dies/is killed.

The problem is that in our testing it appears that some of the signals are not getting through to our handlers. It looks like something -- the perl engine maybe? -- is trapping and ignoring some signals before our handlers have a chance at them. The problem appears to be timing-related. When two signals are generated close together in time (on the order of milliseconds) the first signal never makes it to our code, but the second one does.

Does this scenario ring a bell with anyone out there?

Replies are listed 'Best First'.
•Re: Perl dropping signals?
by merlyn (Sage) on Aug 10, 2004 at 22:37 UTC
    It's probably not Perl. It could very well be the kernel. A signal is only a request that at some point in the future, an interrupt might be taken if the process is interested. The queue is only 1-bit deep... if two signals come in before the interrupt is taken on the first one, the second one is viewed as "redundant" and deleted.

    Thus, never design a protocol where the number of signals matters. Only that a signal has been triggered since the last time you noticed.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      Thanks, Randal! I have a brief (I hope) followup question. Actually, two questions.

      1. Is this behavior the same to your knowledge on all *nixes -- we're using Solaris and Debian Linux.
      2. Does it matter whether the two signals are different signals or the same, i.e., two SIGCHLD's vs a SIGCHLD and SIGUSR2?
Re: Perl dropping signals?
by ysth (Canon) on Aug 11, 2004 at 00:11 UTC