xref: /openbsd-src/regress/lib/libpthread/process_kill/process_kill.c (revision 1fcdd0cd4b3046ceae1c8c25280a594b47775cf6)
1*1fcdd0cdSfgsch /*	$OpenBSD: process_kill.c,v 1.1 2012/03/07 22:01:29 fgsch Exp $	*/
2*1fcdd0cdSfgsch /*
3*1fcdd0cdSfgsch  * Federico G. Schwindt <fgsch@openbsd.org>, 2012. Public Domain.
4*1fcdd0cdSfgsch  */
5*1fcdd0cdSfgsch 
6*1fcdd0cdSfgsch #include <pthread.h>
7*1fcdd0cdSfgsch #include <signal.h>
8*1fcdd0cdSfgsch #include <stdlib.h>
9*1fcdd0cdSfgsch #include <unistd.h>
10*1fcdd0cdSfgsch #include "test.h"
11*1fcdd0cdSfgsch 
12*1fcdd0cdSfgsch void
deadlock(int sig)13*1fcdd0cdSfgsch deadlock(int sig)
14*1fcdd0cdSfgsch {
15*1fcdd0cdSfgsch 	PANIC("deadlock detected");
16*1fcdd0cdSfgsch }
17*1fcdd0cdSfgsch 
18*1fcdd0cdSfgsch void
handler(int sig)19*1fcdd0cdSfgsch handler(int sig)
20*1fcdd0cdSfgsch {
21*1fcdd0cdSfgsch 
22*1fcdd0cdSfgsch }
23*1fcdd0cdSfgsch 
24*1fcdd0cdSfgsch void *
killer(void * arg)25*1fcdd0cdSfgsch killer(void *arg)
26*1fcdd0cdSfgsch {
27*1fcdd0cdSfgsch 	sleep(2);
28*1fcdd0cdSfgsch 	CHECKe(kill(getpid(), SIGUSR1));
29*1fcdd0cdSfgsch 	return (NULL);
30*1fcdd0cdSfgsch }
31*1fcdd0cdSfgsch 
32*1fcdd0cdSfgsch int
main(int argc,char ** argv)33*1fcdd0cdSfgsch main(int argc, char **argv)
34*1fcdd0cdSfgsch {
35*1fcdd0cdSfgsch 	pthread_t t;
36*1fcdd0cdSfgsch 
37*1fcdd0cdSfgsch 	ASSERT(signal(SIGALRM, deadlock) != SIG_ERR);
38*1fcdd0cdSfgsch 	ASSERT(signal(SIGUSR1, handler) != SIG_ERR);
39*1fcdd0cdSfgsch 	CHECKr(pthread_create(&t, NULL, killer, NULL));
40*1fcdd0cdSfgsch 	alarm(5);
41*1fcdd0cdSfgsch 	sleep(15);
42*1fcdd0cdSfgsch 	CHECKr(pthread_join(t, NULL));
43*1fcdd0cdSfgsch 	SUCCEED;
44*1fcdd0cdSfgsch }
45