当前位置: 技术问答>linux和unix
sigqueue发送附加信息无效
来源: 互联网 发布时间:2017-03-10
本文导语: if ( fork() == 0 ) { union sigval sval; char *data = new char[10]; memset(data,0,sizeof(data)); for(int i=0;i si_value.sival_ptr, __FILE__, __LINE__); } int main(int argc, char* const argv[]) { struct sigaction act; char ...
if ( fork() == 0 )
{
union sigval sval;
char *data = new char[10];
memset(data,0,sizeof(data));
for(int i=0;i si_value.sival_ptr, __FILE__, __LINE__);
}
int main(int argc, char* const argv[])
{
struct sigaction act;
char *data;
data = malloc(100);
sprintf(data, "Hello %10d", getpid());
printf("%s [%s:%d]n", data, __FILE__, __LINE__);
act.sa_sigaction = sig_action;
act.sa_flags = SA_SIGINFO;
sigaction(SIGUSR1, &act, NULL);
pid_t pid;
if ((pid = fork()) == -1) {
return 1;
} else if (pid == 0) {
union sigval val;
val.sival_ptr = data;
sprintf(data, "Hello %10d", getpid());
printf("%s [%s:%d]n", data, __FILE__, __LINE__);
sigqueue(getppid(), SIGUSR1, val);
}
while (((pid = wait(0)) == -1 && errno == EINTR) || pid > 0) {
}
return 0;
}
{
union sigval sval;
char *data = new char[10];
memset(data,0,sizeof(data));
for(int i=0;i si_value.sival_ptr, __FILE__, __LINE__);
}
int main(int argc, char* const argv[])
{
struct sigaction act;
char *data;
data = malloc(100);
sprintf(data, "Hello %10d", getpid());
printf("%s [%s:%d]n", data, __FILE__, __LINE__);
act.sa_sigaction = sig_action;
act.sa_flags = SA_SIGINFO;
sigaction(SIGUSR1, &act, NULL);
pid_t pid;
if ((pid = fork()) == -1) {
return 1;
} else if (pid == 0) {
union sigval val;
val.sival_ptr = data;
sprintf(data, "Hello %10d", getpid());
printf("%s [%s:%d]n", data, __FILE__, __LINE__);
sigqueue(getppid(), SIGUSR1, val);
}
while (((pid = wait(0)) == -1 && errno == EINTR) || pid > 0) {
}
return 0;
}
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。