linux不同信号之间发送信号测试
时间:2011-05-01 来源:Leo Chin
#include<stdio.h>
#include<pthread.h>
#include<stdlib.h>
#include<unistd.h>
#include<signal.h>
void *test_program(void *arg);
int main(int argc,char *argv[])
{
int i;
pthread_t thread_id;
void *status;
if(pthread_create(&thread_id,NULL,test_program,NULL)>0)
{
fprintf(stderr,"pthread_create failure\n");
exit(EXIT_FAILURE);
}
sleep(5)
printf("this is parent ,send kill signal to thread %d\n",thread_id);
if(pthread_kill(thread_id,SIGKILL)!=0)
{
perror("pthread_kill");
exit(EXIT_FAILURE);
}
return 0;
}
void *test_program(void *arg)
{
int i;
for(i=0;;i++)
{
sleep(1);
printf("this is child thread ,%d\n",i);
printf("wait for kill signal\n");
}
exit(EXIT_SUCCESS);
}
相关阅读 更多 +