I'm trying to build a basic shell for Unix.
This is the code I use to create a new process:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
pid = fork();
if (pid == 0) {
setpgrp();
complexCommand(argv, isComplex);
}
elseif (pid == -1) { //ERROR
cout << "smash error: > Creating new process failed. Terminating smash..." << endl;
exit(1);
}
else {
jobs.push_back(jobType(argv[0], pid));
if (argv.back().compare("&")) {
fgPid = pid;
int result;
wait(&result);
}
}
Where complexCommand is a function that handles the command (uses execvp after generating the correct string out of argv).
My problem is that after if while in the shell I use a program that needs to print to the screen and handle input, it doesn't work as expected.
To test this, I built this small program:
And when I use the shell I built to run it, the output is only "Enter 2 numbers" for one time. It doesn't print the result, or anything else.
Is there anything I need to do in the parent process (my shell in this case) to give the child the output?