等待信号端
1 #include <signal.h> 2 #include <stdio.h> 3 4 void handle(int sig,siginfo_t* value,void*useless) 5 { 6 printf("%d\n",value->si_value.sival_int); 7 } 8 9 10 int main(int argc, const char *argv[]) 11 { 12 struct sigaction act; 13 sigemptyset(&act.sa_mask); 14 act.sa_sigaction=handle; 15 act.sa_flags=SA_SIGINFO; 16 sigaction(SIGRTMIN,&act,NULL); 17 while(1) 18 { 19 sleep(1); 20 } 21 return 0; 22 }
发送信号端
1 #include <stdio.h> 2 #include <signal.h> 3 int main(int argc, const char *argv[]) 4 { 5 int pid; 6 int i; 7 sigval_t useless_v; 8 scanf("%d",&pid); 9 for (i = 0; i < 20; i++) { 10 useless_v.sival_int=i; 11 if (sigqueue(pid,SIGRTMIN,useless_v)<0) 12 { 13 perror("signale cend failed "); 14 printf("send signal failed \n"); 15 printf(__FILE__); 16 printf("%d\n",__LINE__); 17 } 18 } 19 20 return 0; 21 }