本文整理汇总了C++中sigpending函数的典型用法代码示例。如果您正苦于以下问题:C++ sigpending函数的具体用法?C++ sigpending怎么用?C++ sigpending使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sigpending函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
}
开发者ID:JnuSimba,项目名称:APUE,代码行数:30,代码来源:sigrtime_recv.c
示例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;
}
开发者ID:pugwoo,项目名称:c,代码行数:52,代码来源:sig_test_3.c
示例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;
}
开发者ID:Ferada,项目名称:sbcl,代码行数:50,代码来源:pthreads_win32.c
示例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;
}
开发者ID:chathhorn,项目名称:posixtestsuite,代码行数:32,代码来源:6-1.c
示例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);
}
开发者ID:y-c,项目名称:APUE,代码行数:33,代码来源:critical.c
示例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;
}
开发者ID:zyxstar,项目名称:exam_c,代码行数:25,代码来源:sigpending.c
示例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;
}
开发者ID:mi-rencontre,项目名称:LearnLinux,代码行数:26,代码来源:test.c
示例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;
}
开发者ID:Nan619,项目名称:ltp-ddt,代码行数:33,代码来源:9-1.c
示例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;
}
开发者ID:mikedm195,项目名称:PrograAvanzada,代码行数:30,代码来源:examen2_2.c
示例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");
}
开发者ID:fsxchen,项目名称:CppStudy,代码行数:31,代码来源:mask.c
示例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;
}
开发者ID:JnuSimba,项目名称:APUE,代码行数:35,代码来源:sigrtime_recv.c
示例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;
}
开发者ID:myhongkongzhen,项目名称:LinuxC,代码行数:35,代码来源:6-09mask.c
示例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;
}
开发者ID:gelandesprung,项目名称:reading_notes,代码行数:32,代码来源:e.c
示例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;
}
开发者ID:PoetLiu,项目名称:program,代码行数:33,代码来源:sigpending.c
示例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");
}
开发者ID:ygxqqx,项目名称:practice,代码行数:34,代码来源:mask.c
示例16: main
int main(int argc, const char * argv[])
{
sigset_t conjunto, pendientes;
int i;
sigemptyset(&conjunto);
sigaddset(&conjunto, SIGINT);
sigprocmask(SIG_BLOCK, &conjunto, NULL);
for( i= 0; i < 10; ++i)
{
printf("La señal SIGINT está bloqueada ... \n");
sleep(1);
sigpending(&pendientes);
if (sigismember(&pendientes, SIGINT))
printf("He recibido un Ctrl+C y no lo procesé por estar bloqueada. \n");
}
sigprocmask(SIG_UNBLOCK, &conjunto, NULL);
printf("Ya se desbloqueó la señal");
while(1);
return 0;
}
开发者ID:tuffk,项目名称:ProgramacionAvanzada,代码行数:29,代码来源:bloksigs.c
示例17: main
void main(int args, char * argv[]){
int errn;
setenv("SLEEP_SECS","7",1);
char * sleep_secs=getenv("SLEEP_SECS");
if(sleep_secs==NULL){
errn=errno;
printf("getenv:\t%s\n",strerror(errn));
}
int sl_sc;
printf("sleep secs:\t%s\n",sleep_secs);
sscanf(sleep_secs,"%d",&sl_sc);
sigset_t set;
sigset_t pending;
sigemptyset(&set);
sigaddset(&set,SIGINT);
sigaddset(&set,SIGTSTP);
sigprocmask(SIG_BLOCK,&set,NULL);
printf("going to sleep\n");
sleep(sl_sc);
sigpending(&pending);
if(sigismember(&pending,SIGINT))
printf("SIGINT\n");
if(sigismember(&pending,SIGTSTP)){
printf("SIGTSTP\n");
sigemptyset(&set);
sigaddset(&set,SIGINT);
sigprocmask(SIG_BLOCK,&set,NULL);
}
printf("reanuda y muere\n");
}
开发者ID:pilotAlpal,项目名称:fdi_so,代码行数:30,代码来源:bloquea.c
示例18: main
main() {
sigset_t new_mask, old_mask, pending_mask;
struct sigaction act;
sigemptyset(&act.sa_mask);
act.sa_flags = SA_SIGINFO;
act.sa_sigaction = (void*) user_func;
if (sigaction(SIGRTMIN + 10, &act, NULL))
printf("install signal SIGRTMIN+10 error\n");
sigemptyset(&new_mask);
sigaddset(&new_mask, SIGRTMIN + 10);
if (sigprocmask(SIG_BLOCK, &new_mask, &old_mask))
printf("block signal SIGRTMIN+10 error\n");
sleep(20);
printf("\n\nNow begin to get pending mask and unblock SIGRTMIN+10\n\n");
if (sigpending(&pending_mask) < 0)
printf("get pending mask error\n");
if (sigismember(&pending_mask, SIGRTMIN + 10))
printf("signal SIGRTMIN+10 is pending\n");
if (sigprocmask(SIG_SETMASK, &old_mask, NULL) < 0)
printf("unblock signal error\n");
printf("signal unblocked ,ok ... ...\n\n\n");
}
开发者ID:wyrover,项目名称:MyPaper,代码行数:30,代码来源:testsig2.c
示例19: pq_reset_sigpipe
/*
* Discard any pending SIGPIPE and reset the signal mask.
*
* Note: we are effectively assuming here that the C library doesn't queue
* up multiple SIGPIPE events. If it did, then we'd accidentally leave
* ours in the queue when an event was already pending and we got another.
* As long as it doesn't queue multiple events, we're OK because the caller
* can't tell the difference.
*
* The caller should say got_epipe = FALSE if it is certain that it
* didn't get an EPIPE error; in that case we'll skip the clear operation
* and things are definitely OK, queuing or no. If it got one or might have
* gotten one, pass got_epipe = TRUE.
*
* We do not want this to change errno, since if it did that could lose
* the error code from a preceding send(). We essentially assume that if
* we were able to do pq_block_sigpipe(), this can't fail.
*/
void
pq_reset_sigpipe(sigset_t *osigset, bool sigpipe_pending, bool got_epipe)
{
int save_errno = SOCK_ERRNO;
int signo;
sigset_t sigset;
/* Clear SIGPIPE only if none was pending */
if (got_epipe && !sigpipe_pending)
{
if (sigpending(&sigset) == 0 &&
sigismember(&sigset, SIGPIPE))
{
sigset_t sigpipe_sigset;
sigemptyset(&sigpipe_sigset);
sigaddset(&sigpipe_sigset, SIGPIPE);
sigwait(&sigpipe_sigset, &signo);
}
}
/* Restore saved block mask */
pthread_sigmask(SIG_SETMASK, osigset, NULL);
SOCK_ERRNO_SET(save_errno);
}
开发者ID:jarulraj,项目名称:postgres-cpp,代码行数:45,代码来源:fe-secure.c
示例20: main
int main(int argc,char **argv)
{
sigset_t sigset;
sigset_t pendingset;
int i = 0;
sigfillset(&sigset);
sigprocmask(SIG_BLOCK,&sigset,&pendingset);
printf("My PID %d\n",getpid());
while(1)
{
printf("%d\n",i);
i++;
sleep(1);
if(sigpending(&pendingset) == 0)
{
if(sigismember(&pendingset,SIGUSR1))
{
printf("BLOCK Signal : SIGUSR1\n");
break;
}
}
}
return 0;
}
开发者ID:tlqaksqhr,项目名称:portfolio,代码行数:30,代码来源:sigismember.cpp
注:本文中的sigpending函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论