10.13 sigpending function

Source: Internet
Author: User


The function sigpending is blocked and the process that is currently called by the function hangs the signal set, which is returned by the parameter set.

    1. #include<signal.h>
    2. int sigpending(sigset_t*set);
    3. Returns:0if OK,-1 on error.

Example
  1. #include"apue.h"
  2. staticvoid sig_quit(int);
  3. int main(void)
  4. {
  5. sigset_t newmask,oldmask,pendmask;
  6. if(signal(SIGQUIT, sig_quit)== SIG_ERR)
  7. err_sys("can‘t catch SIGQUIT");
  8. /*
  9. * Block SIGQUIT and save current signal mask
  10. *
  11. */
  12. sigemptyset(&newmask);
  13. sigaddset(&newmask, SIGQUIT);
  14. if(sigprocmask(SIG_BLOCK,&newmask,&oldmask)<0)
  15. err_sys("SIG_BLOCK error");
  16. sleep(5);/*SIGOUT here will remain pending*/
  17. if(sigpending(&pendmask)<0)
  18. err_sys("sigpending error");
  19. if(sigismember(&pendmask, SIGQUIT))
  20. printf("\nSIGQUIT pending\n");
  21. /*
  22. * Restore signal mask whick unblocks SIGQUIT.
  23. */
  24. if(sigprocmask(SIG_SETMASK,&oldmask, NULL)<0)
  25. err_sys("SIG_SETMASK error");
  26. printf("SIGQUIT unblocked\n");
  27. sleep(5);/*SIGQUIT here will terminate with core file */
  28. exit(0);
  29. }
  30. staticvoid sig_quit(int signo)
  31. {
  32. printf("caught SIGQUIT\n");
  33. if(signal(SIGQUIT, SIG_DFL)== SIG_ERR)
  34. err_sys("can‘t reset SIGQUIT");
  35. }

Execution effects such as:

  1. [email protected]:~/UnixProgram/Chapter10$./10_15.exe
  2. ^\^\^\
  3. SIGQUIT pending
  4. caught SIGQUIT
  5. SIGQUIT unblocked
  6. ^\Quit
  7. [email protected]:~/UnixProgram/Chapter10$./10_15.exe
  8. SIGQUIT unblocked
  9. [email protected]:~/UnixProgram/Chapter10$



From for notes (Wiz)



10.13 sigpending function

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.