-
Notifications
You must be signed in to change notification settings - Fork 2
/
exec_clock.c
60 lines (56 loc) · 1.12 KB
/
exec_clock.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
#include<stdio.h>
#include<unistd.h>
#include<errno.h>
#include<stdlib.h>
int exec_clock(int interval,int times)
{
char datePath[1024] = {"/sys/class/rtc/rtc0/date"};
char timePath[1024] = {"/sys/class/rtc/rtc0/time"};
char curr_date[128];
char curr_time[128];
pid_t pid,wpid;
pid = fork();
if(pid<0)
{
//fork error
perror("It's PK's Shell");
_exit(1);
}
else if(!pid)
{
int count = 0;
while(count++ < times)
{
FILE *date = fopen(datePath,"r");
if(!date)
{
printf("Its_PKs_Shell:Unable to open rtc log\n");
perror("Its_PKs_Shell");
_exit(1);
}
FILE *time = fopen(timePath,"r");
if(!time)
{
printf("Its_PKs_Shell:Unable to open rtc log\n");
perror("Its_PKs_Shell");
_exit(1);
}
fscanf(date,"%s",curr_date);
fscanf(time,"%s",curr_time);
printf("%s, %s\n",curr_date,curr_time);
fclose(date);
fclose(time);
//sleep
sleep(interval);
}
_exit(0);
}
else
{
int status;
do{
wpid = waitpid(pid,&status,WUNTRACED);
} while(!WIFEXITED(status) && !WIFSIGNALED(status));
}
return 0;
}