-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclockfn.c
More file actions
47 lines (43 loc) · 970 Bytes
/
Copy pathclockfn.c
File metadata and controls
47 lines (43 loc) · 970 Bytes
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
#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<unistd.h>
#include<fcntl.h>
#include<signal.h>
#include"shell.h"
static volatile int keeprun = 1;
void inthandler(int dummy){
keeprun = 0;
}
void clockfn(char** args, int lowerind){
int timer;
if(args[lowerind+1]==NULL || args[lowerind+1][0]=='\0'){
perror("Invalid command");
return;
}
sscanf(args[lowerind+1], "%d", &timer);
if(timer<=0){
perror("Invalid command");
return;
}
else{
char* buffer = (char*)malloc(sizeof(char)*10);
buffer[0]='\0';
signal(SIGINT, inthandler);
signal(SIGTSTP, inthandler);
while(keeprun){
int datefd = open("/sys/class/rtc/rtc0/date", O_RDONLY);
int timefd = open("/sys/class/rtc/rtc0/time", O_RDONLY);
read(datefd, buffer, 10);
buffer[10]='\0';
printf("%s, ", buffer);
read(timefd, buffer, 8);
buffer[8]='\0';
printf("%s\n", buffer);
sleep(timer);
close(datefd);
close(timefd);
}
}
}