-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexec_reminder.h
More file actions
35 lines (35 loc) · 874 Bytes
/
exec_reminder.h
File metadata and controls
35 lines (35 loc) · 874 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
int exec_reminder(char **cmd)
{
char **argv = argumentize(cmd);
int argc = argCount(argv);
pid_t pid,wpid;
//background is defined when last argument is &
int waitDuration = atoi(argv[1]);
pid = fork();
if(pid<0)
{
//fork error
perror("It's PK's Shell");
_exit(1);
}
else if(!pid)
{
//child process should call execvp
int check = sleep(waitDuration);
if(check>0)
{
perror("It's PK's Shell");
//If not killed multiple copies of shell would open
_exit(1);
}
}
else
{
//parent process for background Process
backgroundProcess[processPointer].pid = pid;
strcpy(backgroundProcess[processPointer].cmd,argv[0]);
processPointer++;
printf("%s [%d]\n",argv[0],pid);
}
return 0;
}