summaryrefslogtreecommitdiffstats
path: root/regress/lib/libpthread/process_kill/process_kill.c
blob: 5110636283885fc59a5f99e5730a34c5d2a90e9f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*	$OpenBSD: process_kill.c,v 1.1 2012/03/07 22:01:29 fgsch Exp $	*/
/*
 * Federico G. Schwindt <fgsch@openbsd.org>, 2012. Public Domain.
 */

#include <pthread.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include "test.h"

void
deadlock(int sig)
{
	PANIC("deadlock detected");
}

void
handler(int sig)
{

}

void *
killer(void *arg)
{
	sleep(2);
	CHECKe(kill(getpid(), SIGUSR1)); 
	return (NULL);
}

int
main(int argc, char **argv)
{
	pthread_t t;

	ASSERT(signal(SIGALRM, deadlock) != SIG_ERR);
	ASSERT(signal(SIGUSR1, handler) != SIG_ERR);
	CHECKr(pthread_create(&t, NULL, killer, NULL));
	alarm(5);
	sleep(15);
	CHECKr(pthread_join(t, NULL));
	SUCCEED;
}