-
Notifications
You must be signed in to change notification settings - Fork 0
/
timerun.c
76 lines (64 loc) · 1.32 KB
/
timerun.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
65
66
67
68
69
70
71
72
73
74
75
/*
* timerun.c
*
* run some simulated time
*
* timeserver
* timeexec program1 args
* timeexec program2 args
* timeexec program3 args
* timerun 20 # run 20 seconds of simulation
* timerun 30 # other 30
* timerun # run until next sleep or unregister
* timerun 100 # other 100 seconds of simulation
* timerun wake # run until next wakeup
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/msg.h>
#include <errno.h>
#include <signal.h>
#include <time.h>
#include <string.h>
#include "timecontrol.h"
/*
* main
*/
int main(int argn, char *argv[]) {
int queue;
key_t key;
int seconds;
int res;
/* argument */
if (argn - 1 < 1 || ! strcmp(argv[1], "sleep"))
seconds = NEXTSLEEP;
else if (! strcmp(argv[1], "wake"))
seconds = NEXTWAKE;
else if (! strcmp(argv[1], "-h")) {
printf("usage:\n\ttimeexec [seconds|\"sleep\"|\"wake\"|-h]\n");
exit(EXIT_SUCCESS);
}
else
seconds = atoi(argv[1]);
/* open queue */
key = ftok(KEYFILE, TIMESERVER);
if (key == -1) {
perror(KEYFILE);
exit(EXIT_FAILURE);
}
queue = msgget(key, 0700);
if (queue == -1) {
perror("msgget");
exit(EXIT_FAILURE);
}
/* run simulation */
msg.mtype = RUN;
msg.time = seconds;
res = msgsnd(queue, &msg, msgsize, 0);
if (res == -1) {
perror("msgsnd");
exit(EXIT_FAILURE);
}
return 0;
}