本文整理汇总了C++中sigpending函数的典型用法代码示例。如果您正苦于以下问题:C++ sigpending函数的具体用法?C++ sigpending怎么用?C++ sigpending使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sigpending函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handler
void handler(int sig)
{
if (sig == SIGINT || sig == SIGRTMIN) {
printf("rev sig=%d\n", sig);
printf("this is SIGINT | SIGRTMIN blockmask\n");
printsigset(&oldset); //即main里面的newset
printsigset(&newset); //block位依然为1
printf("this is SIGINT | SIGRTMIN sigpending\n");
sigpending(&pset); // SIGINT or SIGRTMIN的未决位为0
printsigset(&pset);
}
else if (sig == SIGUSR1) {
sigemptyset(&newset);
sigaddset(&newset, SIGINT);
sigaddset(&newset, SIGRTMIN);
sigprocmask(SIG_UNBLOCK, &newset, &oldset);
// 上句只是将未决标志位清0,block位依然为1,当处理SIGUSR1期间还会将此位置1
// 此句结束立马先执行SIGINT or SIGRTMIN 的信号处理函数(开辟新的函数栈)
// 再接下去执行
printf("this is SIGUSR1 blockmask\n");
printsigset(&oldset);
printsigset(&newset); //block位依然为1
printf("this is SIGUSR1 sigpending\n");
sigpending(&pset); //信号全部处理完毕,故未决位都为0
printsigset(&pset);
}
}
示例2: main
int main(int argc, char **argv)
{
sigset_t block, pending;
int sig, flag;
/* 设置信号的handler */
signal(MYSIGNAL, sig_handler);
/* 屏蔽此信号 */
sigemptyset(&block);
sigaddset(&block, MYSIGNAL);
printf("block signal\n");
sigprocmask(SIG_BLOCK, &block, NULL);
/* 发两次信号, 看信号将会被触发多少次 */
printf("---> send a signal --->\n");
kill(getpid(), MYSIGNAL);
printf("---> send a signal --->\n");
kill(getpid(), MYSIGNAL);
/* 检查当前的未决信号 */
flag = 0;
sigpending(&pending);
for (sig = 1; sig < NSIG; sig++) {
if (sigismember(&pending, sig)) {
flag = 1;
psignal(sig, "this signal is pending");
}
}
if (flag == 0) {
printf("no pending signal\n");
}
/* 解除此信号的屏蔽, 未决信号将被递送 */
printf("unblock signal\n");
sigprocmask(SIG_UNBLOCK, &block, NULL);
/* 再次检查未决信号 */
flag = 0;
sigpending(&pending);
for (sig = 1; sig < NSIG; sig++) {
if (sigismember(&pending, sig)) {
flag = 1;
psignal(sig, "a pending signal");
}
}
if (flag == 0) {
printf("no pending signal\n");
}
return 0;
}
示例3: futex_wait
int
futex_wait(volatile intptr_t *lock_word, intptr_t oldval, long sec, unsigned long usec)
{
struct thread_wakeup w;
pthread_t self = pthread_self();
DWORD msec = sec<0 ? INFINITE : (sec*1000 + usec/1000);
DWORD wfso;
int result;
sigset_t pendset, blocked;
int maybeINTR;
int info = sec<0 ? WAKEUP_WAITING_NOTIMEOUT: WAKEUP_WAITING_TIMEOUT;
sigpending(&pendset);
if (pendset & ~self->blocked_signal_set)
return FUTEX_EINTR;
w.uaddr = lock_word;
w.uval = oldval;
w.info = info;
if (cv_wakeup_add(&futex_pseudo_cond,&w)) {
return FUTEX_EWOULDBLOCK;
}
self->futex_wakeup = &w;
do {
wfso = WaitForSingleObject(w.event, msec);
} while (wfso == WAIT_OBJECT_0 && w.info == info);
self->futex_wakeup = NULL;
sigpending(&pendset);
maybeINTR = (pendset & ~self->blocked_signal_set)? FUTEX_EINTR : 0;
switch(wfso) {
case WAIT_TIMEOUT:
if (!cv_wakeup_remove(&futex_pseudo_cond,&w)) {
/* timeout, but someone other removed wakeup. */
result = maybeINTR;
WaitForSingleObject(w.event,INFINITE);
} else {
result = FUTEX_ETIMEDOUT;
}
break;
case WAIT_OBJECT_0:
result = maybeINTR;
break;
default:
result = -1;
break;
}
futex_pseudo_cond.return_fn(w.event);
return result;
}
示例4: main
int main()
{
sigset_t pendingset;
struct sigaction act;
act.sa_handler = myhandler;
act.sa_flags = 0;
sigemptyset(&act.sa_mask);
if (sigaction(SIGCHLD, &act, 0) != 0) {
perror("Unexpected error while using sigaction()");
return PTS_UNRESOLVED;
}
if (sigset(SIGCHLD,SIG_HOLD) != SIG_HOLD) {
perror("Unexpected error while using sigset()");
return PTS_UNRESOLVED;
}
raise(SIGCHLD);
if (sigpending(&pendingset) == -1) {
printf("Error calling sigpending()\n");
return PTS_UNRESOLVED;
}
if (sigismember(&pendingset, SIGCHLD) != 1) {
printf("Test FAILED: Signal SIGCHLD was not successfully blocked\n");
return PTS_FAIL;
}
return PTS_PASS;
}
示例5: main
int
main(void)
{
sigset_t newmask, oldmask, pendmask;
if (signal(SIGQUIT, sig_quit) == SIG_ERR)
err_sys("can't catch SIGQUIT");
/*
* Block SIGQUIT and save current signal mask.
*/
sigemptyset(&newmask);
sigaddset(&newmask, SIGQUIT);
if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
err_sys("SIG_BLOCK error");
sleep(5); /* SIGQUIT here will remain pending */
if (sigpending(&pendmask) < 0)
err_sys("sigpending error");
if (sigismember(&pendmask, SIGQUIT))
printf("\nSIGQUIT pending\n");
/*
* Reset signal mask which unblocks SIGQUIT.
*/
if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
err_sys("SIG_SETMASK error");
printf("SIGQUIT unblocked\n");
sleep(5); /* SIGQUIT here will terminate with core file */
exit(0);
}
示例6: main
int main(void)
{
sigset_t set, oset, pend;
int i;
sigemptyset(&set);
sigaddset(&set, SIGINT);
sigprocmask(SIG_BLOCK, &set, &oset);
for (i = 0; ; i++) {
if (i == 10) {
sigprocmask(SIG_SETMASK, &oset, NULL);
}
sleep(1);
sigpending(&pend);
if (sigismember(&pend, SIGINT)) {
printf("i = %d, SIGINT pending\n", i);
} else {
printf("i = %d\n", i);
}
}
return 0;
}
示例7: main
int main()
{
signal(2, handler);
sigset_t s, p, o;
sigemptyset(&s);
sigemptyset(&o);
sigaddset(&s, SIGINT);
sigprocmask(SIG_SETMASK, &s, &o);
int count = 0;
while(1)
{
sigemptyset(&p);
sigpending(&p);
print_sig(&p);
sleep(1);
if(count++ == 10)
{
sigprocmask(SIG_SETMASK, &o, NULL);
printf("recover block\n");
sleep(3);
}
}
return 0;
}
示例8: main
int main()
{
struct sigaction act;
sigset_t pendingset, selectset;
act.sa_flags = 0;
act.sa_handler = myhandler;
sigemptyset(&pendingset);
sigemptyset(&selectset);
sigaddset(&selectset, SIGTOTEST);
sigemptyset(&act.sa_mask);
sigaction(SIGTOTEST, &act, 0);
sighold(SIGTOTEST);
raise(SIGTOTEST);
sigpending(&pendingset);
if (sigismember(&pendingset, SIGTOTEST) != 1) {
perror("SIGTOTEST is not pending\n");
return PTS_UNRESOLVED;
}
if (sigwaitinfo(&selectset, NULL) != SIGTOTEST) {
perror("Call to sigwaitinfo() failed\n");
return PTS_FAIL;
}
printf("Test PASSED\n");
return PTS_PASS;
}
示例9: main
int main(int argc, char *argv[]){
int i = 0;
sigset_t mask, pending;
sigfillset(&mask);
sigdelset(&mask, SIGALRM);
sigprocmask(SIG_SETMASK, &mask, NULL);
signal(SIGALRM, SIG_DFL);
alarm(2);
signal(SIGALRM, control_alarm);
existe();
while(i < ndir){
printf("Creando\n");
int signal;
grabar = 1;
sprintf(buffer, "./datos/a%d", i);
i++;
file = fopen(buffer, "w+");
alarm(temp);
while(grabar)
fputc('x', file);
sigpending(&pending);
for(signal = 1; signal < NSIG; signal++)
if(sigismember(&pending, signal))
fprintf(file, "\nWas blocked: the signal %d\n", signal);
fclose(file);
}
imprimir();
printf("\n");
return 0;
}
示例10: main
main() {
int sum = 0;
int i;
//1.声明
signal(SIGINT, h);
sigset_t sigs, sigp, sigq;
sigemptyset(&sigs);
sigemptyset(&sigp);
sigemptyset(&sigq);
sigaddset(&sigs, SIGINT);
sigprocmask(SIG_BLOCK, &sigs, 0);
for(i = 1; i <= 10; i++) {
sum += i;
sigpending(&sigp);
if(sigismember(&sigp, SIGINT)) {
printf("SIGINT信号在排队\n");
sigsuspend(&sigq); //这里等待信号处理,这么写的好处。你可以控制信号中断的位置
//+代码必须在这里中断。
//使原来屏蔽信号无效,开放原来信号
//使新的信号屏蔽,
//当某个信号处理函数处理完毕
//sigsuspend恢复原来屏蔽信号,返回
}
sleep(1);
}
printf("sum=%d\n", sum);
sigprocmask(SIG_UNBLOCK, &sigs, 0);
printf("over!\n");
}
示例11: main
int main(int argc, char *argv[])
{
struct sigaction act;
act.sa_handler = handler;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
sigset_t pset, oldset, newset;
sigemptyset(&newset);
sigaddset(&newset, SIGINT);
sigaddset(&newset, SIGRTMIN);
sigprocmask(SIG_BLOCK, &newset, &oldset);
// 将block位置1,因为信号尚未产生,此时未决位都为0
if (sigaction(SIGINT, &act, NULL) < 0)
ERR_EXIT("sigaction error");
if (sigaction(SIGRTMIN, &act, NULL) < 0)
ERR_EXIT("sigaction error");
if (sigaction(SIGUSR1, &act, NULL) < 0)
ERR_EXIT("sigaction error");
for (; ;) {
printf("this is main blockmask\n");
printsigset(&oldset); //全0
printsigset(&newset); //两位为1
printf("this is main sigpending\n");
sigpending(&pset);
printsigset(&pset); // 全0
sleep(1);
}
return 0;
}
示例12: main
int main(){
int sum = 0;
int i;
sigset_t sigs;
sigset_t sigp;
sigset_t sigq;
sigemptyset(&sigs);
sigemptyset(&sigp);
sigemptyset(&sigq);
signal(SIGINT,h);
sigaddset(&sigs,SIGINT);
sigprocmask(SIG_BLOCK,&sigs,0);
for(i = 1 ; i <= 10 ; i++){
sum += 1;
printf("%d\n",sum);
sigpending(&sigp);
if(sigismember(&sigp,SIGINT)){
printf("SIGINT is queue....\n");
sigsuspend(&sigq);
}
sleep(1);
}
printf("----%d\n",sum);
sigprocmask(SIG_UNBLOCK,&sigs,0);
printf("over!\n");
while(1);
return 0;
}
示例13: main
int
main ()
{
sigset_t set, oset;
signal (SIGQUIT, mytest);
sigemptyset (&set);
sigemptyset (&oset);
sigaddset (&set, SIGQUIT);
if (sigprocmask (SIG_BLOCK, &set, &oset) == -1)
{
perror ("sigprocmask");
return -1;
}
printf ("pid=%d\n", getpid ());
sleep (10);
sigemptyset (&set);
if (!sigpending (&set))
{
if (sigismember (&set, SIGQUIT))
{
printf ("sigquit\n");
}
}
if (sigprocmask (SIG_SETMASK, &oset, NULL) == -1)
{
perror ("sigprocmask");
return -1;
}
printf ("end\n");
return 0;
}
示例14: main
int main(void)
{
sigset_t newmask, oldmask, pendmask;
if (signal(SIGQUIT, sig_quit) == SIG_ERR)
printf("can't catch SIGQUIT\n");
/*
* Block SIGQUIT and save current signal mask.
*/
sigemptyset(&newmask);
sigaddset(&newmask, SIGQUIT);
if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
printf("SIG_BLOCK error\n");
sleep(5);
if (sigpending(&pendmask) < 0)
printf("sigpending error\n");
if (sigismember(&pendmask, SIGQUIT))
printf("SIGQUIT pending\n");
/*
* Reset signal mask which unblock SIGQUIT.
*/
if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
printf("SIG_SETMASK error\n");
printf("SIGQUIT unblocked\n");
sleep(5);
return 0;
}
示例15: main
main()
{
int sum=0;
int i;
//1.
signal(SIGINT,h);
sigset_t sigs,sigp,sigq;
//2.
sigemptyset(&sigs);
sigemptyset(&sigp);
sigemptyset(&sigq);
sigaddset(&sigs,SIGINT);
//3.
sigprocmask(SIG_BLOCK,&sigs,0);
for(i=1;i<=10;i++)
{
sum+=i;
sigpending(&sigp);
if(sigismember(&sigp,SIGINT))
{
printf("SIGINT在排队!\n");
sigsuspend(&sigq);
//使原来屏蔽信号无效,开放原来信号
//使新的信号屏蔽,
//当某个信号处理函数处理完毕
//sigsuspend恢复原来屏蔽信号,返回
}
sleep(1);
}
printf("sum=%d\n",sum);
sigprocmask(SIG_UNBLOCK,&sigs,0);
printf("Over!\n");
}