Linux under C Programming: sigsuspend process blocking

Source: Internet
Author: User
Tags exit include printf linux

int sigsuspend (const sigset_t *sigmask);

This function is used to suspend the process, and sigmask points to a set of signals. When this function is invoked, the signal in the signal set that the Sigmask points to is assigned to the signal mask. The process hangs afterwards. The function Sigsuspend returns when the process catches the signal and calls the handler function to return. The signal mask reverts to the value before the signal call, while the errno is set to Eintr. The process end signal can stop it immediately.

#include <stdio.h> #include <signal.h> void Checkset ();     
void Func ();     
     void Main () {sigset_tblockset,oldblockset,zeroset,pendmask;     
     printf ("pid:%ld\n", (long) getpid ());     
         
     Signal (SIGINT,FUNC);     
     Sigemptyset (&blockset);     
     Sigemptyset (&zeroset);     
         
     Sigaddset (&blockset,sigint);     
     Sigprocmask (Sig_setmask,&blockset,&oldblockset);     
     Checkset ();     
         
     Sigpending (&pendmask);     
         
     if (Sigismember (&pendmask,sigint)) printf ("sigintpending\n");     
     if (Sigsuspend (&zeroset)!=-1) {printf ("sigsuspenderror\n");     
     Exit (0);     
     printf ("afterreturn\n");     
         
     Sigprocmask (Sig_setmask,&oldblockset,null);     
printf ("sigintunblocked\n");     
     } void Checkset () {sigset_tset; printf ("CheckSetstart:\n "); if (Sigprocmask (0,null,&set) <0) {printf ("Checksetsigprocmask error!!     
     \ n ");     
     Exit (0);     
         
     } if (Sigismember (&set,sigint)) printf ("sigint\n");     
         
     if (Sigismember (&AMP;SET,SIGTSTP)) printf ("sigtstp\n");     
     if (Sigismember (&set,sigterm)) printf ("sigterm\n");     
printf ("checksetend\n");     
} void Func () {printf ("hellofunc\n"); }

View a full set of articles: Http://www.bianceng.cn/Programming/C/201212/34807.htm

Related Article

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.