Friday, October 22, 2010

[nslu2-linux] Re: Sigwait

 



--- 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.

__._,_.___
Recent Activity:
MARKETPLACE

Hobbies & Activities Zone: Find others who share your passions! Explore new interests.


Stay on top of your group activity without leaving the page you're on - Get the Yahoo! Toolbar now.


Get great advice about dogs and cats. Visit the Dog & Cat Answers Center.

.

__,_._,___

No comments:

Post a Comment