Tellwait. c

Source: Internet
Author: User
Tags signal handler

# Include "apue. H "</P> <p> static volatile sig_atomic_t sigflag;/* Set nonzero by sig handler */<br/> static sigset_t newmask, oldmask, and zeromask; </P> <p> static void <br/> sig_usr (INT signo) /* one signal handler for SIGUSR1 and sigusr2 */<br/> {<br/> sigflag = 1; <br/>}</P> <p> void <br/> tell_wait (void) <br/>{< br/> If (signal (SIGUSR1, sig_usr) = sig_err) <br/> err_sys ("signal (SIGUSR1) error"); <br/> If (signal (sigusr2, sig_usr) = sig_err) <br/> err_sys ("signal (sigusr2) error"); <br/> sigemptyset (& zeromask); <br/> sigemptyset (& newmask ); <br/> sigaddset (& newmask, SIGUSR1); <br/> sigaddset (& newmask, sigusr2 ); </P> <p>/* <br/> * block SIGUSR1 and sigusr2, and save current signal mask. <br/> */<br/> If (sigprocmask (sig_block, & newmask, & oldmask) <0) <br/> err_sys ("sig_block error "); <br/>}</P> <p> void <br/> tell_parent (pid_t PID) <br/>{< br/> kill (PID, sigusr2 ); /* Tell parent we're done */<br/>}</P> <p> void <br/> wait_parent (void) <br/>{< br/> while (sigflag = 0) <br/> sigsuspend (& zeromask ); /* and wait for parent */<br/> sigflag = 0; </P> <p>/* <br/> * reset signal mask to original value. <br/> */<br/> If (sigprocmask (sig_setmask, & oldmask, null) <0) <br/> err_sys ("sig_setmask error "); <br/>}</P> <p> void <br/> tell_child (pid_t PID) <br/>{< br/> kill (PID, SIGUSR1 ); /* Tell child we're done */<br/>}</P> <p> void <br/> wait_child (void) <br/>{< br/> while (sigflag = 0) <br/> sigsuspend (& zeromask ); /* and wait for child */<br/> sigflag = 0; </P> <p>/* <br/> * reset signal mask to original value. <br/> */<br/> If (sigprocmask (sig_setmask, & oldmask, null) <0) <br/> err_sys ("sig_setmask error "); <br/>}< br/>  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.