网站维护一般多久网站空间去哪买
网站维护一般多久,网站空间去哪买,衡水林熠网站建设公司,wordpress 糗百一、函数sigqueue
sigqueue函数原型#xff1a;
函数作用#xff1a;新的发送信号系统调用#xff0c;主要是针对实时信号提出的支持信号带有参数#xff0c;与函数sigaction#xff08;#xff09;配合使用
int sigqueue(pid_t pid, int signo, const union sigval v…一、函数sigqueue
sigqueue函数原型
函数作用新的发送信号系统调用主要是针对实时信号提出的支持信号带有参数与函数sigaction配合使用
int sigqueue(pid_t pid, int signo, const union sigval value);分析
第一个参数 指定接收信号的进程id第二个参数确定即将发送的信号第三个参数是一个联合结构体union sigval指定了信号传递的参数即通常所说的4字节值
二、程序清单
1. 测试代码
发送端程序代码
#include string.h
#include signal.h
#include unistd.h
#include stdlib.h
#include stdio.hvoid handler(int, siginfo_t *, void*);int main(int argc, char *argv[])
{printf(Im %d\n, getpid());struct sigaction act;act.sa_sigaction handler;sigemptyset(act.sa_mask);act.sa_flags SA_SIGINFO;if(sigaction(SIGINT, act, NULL) 0) {perror(sigaction error);exit(0);}for(; ;)pause();return 0;
}void handler(int sig, siginfo_t *info, void *ctx)
{printf(recv a sig %d data %d data %d\n, sig, info-si_value.sival_int, info-si_int);
}
接收端程序代码
#include stdlib.h
#include stdio.h
#include string.h
#include signal.h
#include unistd.hint main(int argc, char *argv[])
{if(argc ! 2) {fprintf(stderr, Usage %s pid\n, argv[0]);exit(0);}pid_t pid atoi(argv[1]);union sigval v;v.sival_int 100;sigqueue(pid, SIGINT, v);sleep(3);return 0;}
输出结果
发送端 接收端 2. 测试代码
发送端程序
#include stdlib.h
#include stdio.h
#include string.h
#include signal.h
#include unistd.hint main(int argc, char *argv[])
{if(argc ! 2) {fprintf(stderr, Usage %s pid\n, argv[0]);exit(0);}pid_t pid atoi(argv[1]);union sigval v;v.sival_int 100;sigqueue(pid, SIGINT, v);sigqueue(pid, SIGINT, v);sigqueue(pid, SIGINT, v);sigqueue(pid, SIGRTMIN, v);sigqueue(pid, SIGRTMIN, v);sigqueue(pid, SIGRTMIN, v);sleep(3);kill(pid, SIGUSR1);return 0;
}
接收端程序
#include string.h
#include signal.h
#include unistd.h
#include stdlib.h
#include stdio.hvoid handler(int sig);int main(int argc, char *argv[])
{printf(Im %d\n, getpid());struct sigaction act;act.sa_sigaction handler;sigemptyset(act.sa_mask);act.sa_flags 0;sigset_t s;sigemptyset(s);sigaddset(s, SIGINT);sigaddset(s, SIGRTMIN);sigprocmask(SIG_BLOCK, s, NULL);if(sigaction(SIGINT, act, NULL) 0) {perror(sigaction error);exit(0);}if(sigaction(SIGRTMIN, act, NULL) 0) {perror(sigaction error);exit(0);}if(sigaction(SIGUSR1, act, NULL) 0) {perror(sigaction error);exit(0);}for(; ;)pause();return 0;
}void handler(int sig)
{if(sig SIGINT || sig SIGRTMIN) printf(recv a sig %d\n, sig);else if(sig SIGUSR1){sigset_t s;sigemptyset(s);sigaddset(s, SIGINT);sigaddset(s, SIGRTMIN);sigprocmask(SIG_UNBLOCK, s, NULL); }
}
输出结果
发送端 接收端
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/87205.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!