-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtsahr.c
More file actions
53 lines (43 loc) · 1.29 KB
/
tsahr.c
File metadata and controls
53 lines (43 loc) · 1.29 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
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <time.h>
#include <string.h>
void timer_handler(int sig) {
// Signal handler for timer expiration
printf("Timer expired!\n");
}
int main(int argc, char *argv[]) {
int timer_seconds = 0;
int record_count = 0;
if (argc > 2 && strcmp(argv[1], "-s") == 0) {
timer_seconds = atoi(argv[2]);
if (timer_seconds < 0) {
fprintf(stderr, "Invalid timer value: %s\n", argv[2]);
exit(1);
}
} else if (argc > 1) {
fprintf(stderr, "Usage: %s -s <seconds>\n", argv[0]);
exit(1);
}
signal(SIGALRM, timer_handler);
time_t start_time = time(NULL);
while (1) {
// Call ahr stamp
system("/home/<USER>/uCode/ahr");
record_count++;
// Check if timer has expired
time_t current_time = time(NULL);
if (difftime(current_time, start_time) >= timer_seconds) {
break;
}
}
printf("Total records printed in %d seconds: %d\n", timer_seconds, record_count);
// Print one stamp by default if no timer is specified
if (timer_seconds == 0) {
system("/home/<USER>/uCode/ahr");
printf("Use tsahr -s <seconds> to specify a duration\n");
}
return 0;
}