-
Notifications
You must be signed in to change notification settings - Fork 6
/
sigcont.c
64 lines (57 loc) · 1008 Bytes
/
sigcont.c
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Tacy Bechtel
// SIGCONT
#include <stdio.h>
#include <signal.h>
#include <time.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <sys/wait.h>
void
sigcont(int signo)
{
printf("SIGCONT received\n");
}
int
test_sigcont(void)
{
int count = 0;
int pid;
struct sigaction sa;
sigfillset(&sa.sa_mask);
sigdelset(&sa.sa_mask, SIGTSTP);
sigdelset(&sa.sa_mask, SIGCONT);
sa.sa_handler = &sigcont;
if ((pid = fork()) < 0)
{
printf("Fork failure\n");
return -1;
}
else if (pid == 0)
{
sigaction(SIGCONT, &sa, NULL);
while (1)
{
printf("Child running\n");
sleep(1);
}
}
else
{
printf("Parent running\n");
while (count < 3) {
sleep(5);
printf("Sending SIGTSTP to child\n");
kill(pid, SIGTSTP);
sleep(3);
printf("Sending child Continue\n");
kill(pid, SIGCONT);
count++;
}
sleep(3);
printf("Exiting\n");
kill(pid, SIGKILL);
wait(NULL);
}
return 0;
}