I'm writing a pseudo shell program which creates a child from a parent process. The parent process waits for the child to finish before continuing. My forking code looks something like this:
if(fork()==0)
{
execvp(cmd, args);
}
else
{
int status = 0;
wait(&status);
printf("Child exited with status of %d\n", status);
}
But, I want to be able to parse the '&' operator, such that if a user enters it at the end of a command line, the parent won't wait for the child before prompting the user for another command. I added some code to handle this, but I wasn't exactly sure if it's working right. Would it look something like:
if(fork()==0)
{
execvp(cmd, args);
}
else
{
if(andOp = 1) //boolean to keep track of if '&' was encountered in parsing
{
shellFunc(); //main function to prompt user for a cmd line
}
int status = 0;
wait(&status);
printf("Child exited with status of %d\n", status);
}
Does this actually accomplish the concurrency achieved by the regular shell?