Loading ...
Sorry, an error occurred while loading the content.

Re: Sigwait

Expand Messages
  • clerew5
    ... Replying to my own question, it seems that sigwait expects the signal to be blocked before you attempt to wait upon it. The additional code below shows
    Message 1 of 2 , Oct 22, 2010
    View Source
    • 0 Attachment
      --- In nslu2-linux@yahoogroups.com, "clerew5" <clerew5@...> wrote:
      >
      > The following program works fine on my SPARC solaris system:

      Replying to my own question, it seems that sigwait expects the signal to be 'blocked' before you attempt to wait upon it. The additional code below shows what is needed to make it work. It is still unclear why Solaris worked without it (probably the order in which various things are tested within the kernel).
      >
      > #include <stdio.h>
      > #include <stdlib.h>
      > #include <ctype.h>
      > #include <sys/types.h>
      > #include <unistd.h>
      > #include <signal.h>
      >
      > sigset_t blockset;
      >
      > int count = 0;
      >
      > void
      > take_action(int signal)
      > {
      > printf("%d\n", count++);
      > }
      >
      > main()
      > {
      > int signal;
      > sigemptyset(&blockset);
      > sigaddset(&blockset, SIGUSR1);

      sigprocmask(SIG_BLOCK, &blockset, NULL);
      /* should probably have used pthread_sigmask */

      >
      > while(1) {
      > sigwait(&blockset, &signal);
      > take_action(signal);
      > }
      > }
      >
      > It sits in a loop waiting for a SIGUSR1 signal, and when it comes it prints out that it has seen it. The intention is that if several such signals are received in rapid succession, the first will be actioned and the rest will be queued up and processed on subsequent cycles of the loop.
    Your message has been successfully submitted and would be delivered to recipients shortly.