-
Notifications
You must be signed in to change notification settings - Fork 0
/
reminder.c
88 lines (71 loc) · 1.4 KB
/
reminder.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
76
77
78
79
80
81
82
83
84
85
86
87
88
void exec_remind(char ** cmd_input,int * cmd_count)
{
if(* cmd_count<3)
{
perror("least arguments passed");
}
else
{
pid_t pid;
struct timeval start, end;
gettimeofday(&start, NULL);
double delta;
int background=1,i; // default back ground on
int lapse= atoi(cmd_input[1]);
char buf[100],buf1[100];
if(strcmp(cmd_input[*cmd_count-1], "&") == 0) /* if & is included process running in background*/
{
cmd_input[*cmd_count-1] = NULL;
background = 1;
}
pid=fork();
if(pid < 0)
{
printf("%s\n","child process failed" );
exit(1);
}
else if(pid==0 && background==1)
{
do
{
gettimeofday(&end, NULL);
delta = ((end.tv_sec-start.tv_sec) * 1000000u +end.tv_usec - start.tv_usec) / 1.e6;
}while(delta< lapse);
printf("\nREMINDER:");
sprintf(buf,"%c",cmd_input[2][0]);
if(strcmp(buf,"\"")==0)
{
for(int i=2;cmd_input[i]!=NULL;i++)
{
for(int j=0;j<strlen(cmd_input[i]);j++)
{
sprintf(buf1,"%c",cmd_input[i][j]);
if(!strcmp(buf1,"\"")==0)
{
printf("%s",buf1);
}
}
printf(" ");
}
printf("\n");
}
else
{
for(int i=2;cmd_input[i]!=NULL;i++)
printf("%s ",cmd_input[i]);
printf("\n");
}
exit(1);
}
else
{
exit(1);
}
/* else if (!background)
{
wait(NULL);
exit(1);
}
*/
}
}