-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecute.h
More file actions
60 lines (56 loc) · 1.2 KB
/
execute.h
File metadata and controls
60 lines (56 loc) · 1.2 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
54
55
56
57
58
59
60
#ifndef ba
#define ba
void foreground_proc()
{
int pid = fork();
pname = pid;
if(!pid) {
pname=getpid();
if(execvp(input2[0],input2) < 0){
perror("Can't execute");
}
} else
wait(NULL);
}
void background_proc()
{
int pid = fork();
if(!pid){
int fd = open(paths,O_RDWR | O_APPEND);
int i=0;
char save[1024] = {'\0'};
char store[1024] = {'\0'};
while(input2[i]){
strcat(store,input2[i++]);
strcat(store," ");
}
sprintf(save,"1%d %s[%d]\n",getpid(),store,getpid());
write(fd,save,strlen(save));
close(fd);
if(execvp(input2[0],input2) < 0){
perror("Can't execute");
}
} else{
fprintf(stderr,"[%d]\n",pid);
}
}
void execute(int len)
{
int length = strlen(input[0]);
if (length > 1){
int i = 0;
for(i=0;i<len;i++){
if(input[i][0]=='&'){
input2[i] = NULL;
background_proc();
return;
}
else{
input2[i] = input[i];
}
}
input2[len] = NULL;
foreground_proc();
}
}
#endif