how to use sigsuspend ?

  • Follow


Hello everyone,

I am trying to understand how to use sigsuspend waiting for a signal to 
be detected.
I found 2 interesting examples on the web, which seem to do exactly what 
I need, but I do not quite understand why they are differt and how they 
do act differeclty. By the way, they both work correctly.

Can someone explain me the difference ? Thank you, Cristina

_____________________________________________________________
First example:
(http://vip.cs.utsa.edu/classes/cs3733f2003/notes/USP-08.html)


Example 8.25: a correct way to wait for a signal:
1. static volatile sig_atomic_t sigreceived = 0;

 3. sigset_t maskblocked, maskold, maskunblocked;
 4. int signum = SIGUSR1;

 6. sigprocmask(SIG_SETMASK, NULL, &maskblocked);
 7. sigprocmask(SIG_SETMASK, NULL, &maskunblocked);
 8. sigaddset(&maskblocked, signum);
 9. sigdelset(&maskunblocked, signum);
10. sigprocmask(SIG_BLOCK, &maskblocked, &maskold);
11. while(sigreceived == 0)
12.    sigsuspend(&maskunblocked);
13. sigprocmask(SIG_SETMASK, &maskold, NULL);

_____________________________________________________________
Second example:
(ecealpha.ece.eng.kuniv.edu.kw/~kamal/CpE494/ch5.pdf)


Example:

/* modify the above program to use sigsuspend */
sigset_t newMask, oldMask;
....
sigprocmask(SIG_BLOCK, NULL, &oldMask); /* save old mask*/

/* initialize the new mask which will be used by
sigsuspend to include current signals */
sigprocmask(SIG_BLOCK, NULL, &newMask);

/* block SIGINT */
sigaddset(&newMask, SIGINT);
sigprocmask(SIG_SETMASK, &newMask, NULL);

/* remove SIGINT from mask to be used by sigsuspend */
sigdelset(&newMask, SIGINT);/*form mask to unblock SIGINT*/

while (signalReceived ==0)
    sigsuspend(&newMask);

/* while loop ended; restore the original mask */
sigprocmask(SIG_SETMASK, &oldMask, NULL);

0
Reply cri 2/6/2004 2:28:55 PM


0 Replies
736 Views

(page loaded in 0.017 seconds)

Similiar Articles:






7/23/2012 8:08:02 PM


Reply: