I was asked to simulate the Unix shell in C, and the part of code is following:
int pid, argc=0;
should_wait=0;
argc = makeargv(buffer,args);
if(argc!=0)
if(strcmp(args[argc-1],"&")==0){
args[argc-1]=NULL;
should_wait=1;
}
if(argc!=0)
if((pid=fork())==0){
execvp(args[0],&args[0]);
exit(1);
}
if(should_wait){
printf("parent here\n");
wait(NULL);
printf("Child complete\n");
}
The parent process suppose to wait for the child if input arguments following by &
for example: parent wait child enter ls &
, parent does not wait child enter `ls. However, the output is:
osh>ls &
parent here
Child complete
osh>a.out
argv.c myshell.c
|