linux異なる信号間送信信号テスト
5079 ワード
#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
"
);
exit(EXIT_FAILURE);
}
sleep(
5
)
printf(
"
this is parent ,send kill signal to thread %d
"
,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
"
,i);
printf(
"
wait for kill signal
"
);
}
exit(EXIT_SUCCESS);
}