-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandle.c
More file actions
80 lines (66 loc) · 1.35 KB
/
handle.c
File metadata and controls
80 lines (66 loc) · 1.35 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <time.h>
#include <unistd.h>
#include "util.h"
/*
* First, print out the process ID of this process.
*
* Then, set up the signal handler so that ^C causes
* the program to print "Nice try.\n" and continue looping.
*
* Finally, loop forever, printing "Still here\n" once every
* second.
*/
//Paul is driving
void handler(int sig)
{
ssize_t bytes;
const int STDOUT = 1;
bytes = write(STDOUT, "Nice try.\n", 10);
if(bytes != 10)
exit(-999);
}
// Zoe is driving
void sigusr1_handler(int sig)
{
//print "exiting"
ssize_t bytes;
const int STDOUT = 1;
bytes = write(STDOUT, "exiting\n", 10);
if(bytes != 10)
exit(-999);
// exit with status = 1
exit(1);
}
//void alarmhandler(int sig)
//{
//}
int main(int argc, char **argv)
{
/* print out this process's ID - Zoe is driving*/
pid_t pid;
pid = getpid();
fprintf(stdout, "This process's ID is %d\n", pid);
Signal(SIGINT, handler);
Signal(SIGUSR1, sigusr1_handler);
//Signal(SIGALRM, alarmhandler);
struct timespec req;
req.tv_sec = 1;
struct timespec rem;
req.tv_nsec = 0;
//Paul is driving
//alarm(1);
while(1){
int interrupt = nanosleep(&req, &rem);
printf("%s", "Still here\n");
if(interrupt == -1)
{
nanosleep(&rem, &rem);
}
}
return 0;
}