-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforeground.c
More file actions
33 lines (31 loc) · 784 Bytes
/
foreground.c
File metadata and controls
33 lines (31 loc) · 784 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
#include "headers.h"
void foreground(char* input){
char* temp = (char*) malloc(N);
strcpy(temp, input);
char* here = strtok_r(temp, " ", &temp);
char* store[100];
int cnt = 0;
while(here != NULL){
store[cnt] = (char*) malloc(N);
strcpy(store[cnt++], here);
here = strtok_r(NULL, " ", &temp);
}
store[cnt] = NULL;
pid_t pid = fork();
if(pid < 0){
printf("process could not be executed\n");
return;
}
else{
if(!pid){
if(execvp(store[0], store) == -1){
printf("ERROR : '%s' is not a valid command\n", store[0]);
return;
}
}
else{
int wait;
waitpid(pid, &wait, WUNTRACED);
}
}
}