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 (&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