Ian Cameron Processes#380
Ian Cameron Processes#380codypeak wants to merge 9 commits intobloominstituteoftechnology:masterfrom
Conversation
codejoncode
left a comment
There was a problem hiding this comment.
You have some good looking stuff here. I would only recommend the following if statement,
if (rc < 0) {
fprintf(stderr, "fork failed\n");
exit(1);
}
/*stderr is the standard error stream the default destination for error messages and other diagnostic warnings. Like stdout
it is usually also directed by default to the text console(generally, on the screen).
*/
exit so its prototype looks like this
void exit(int status);
Returns nothing but indicates whehter the program terminated normally.
exit_success successful termination
0 successful termination
exit_failure unsuccessful termination
exit will terminate the program and everything that comes after it will not show up.
codejoncode
left a comment
There was a problem hiding this comment.
Great job here Ian really clean and gets the job done.
codejoncode
left a comment
There was a problem hiding this comment.
For ex4 we want to set up the main to accept argc and argv[] this would be entered in on the command line and read into the program and then worked with accordingly
int main(int argc, char* argv[])
{
printf("Parent process here\n");
int rc = fork();
if (rc < 0) {
fprintf(stderr, "fork failed\n");
exit(1);
} else if (rc == 0) {
printf("Child process here\n");
// execl("/bin/ls", "ls", "-l" (char *) NULL);
// char *args[] = {"ls", "-l", NULL};
// execv("/bin/ls", args);
//execlp("ls", "ls", "-l", (char *) NULL);
char *args[] = {"ls", "-l", NULL};
execvp("ls", args);
} else {
int wc = waitpid(rc, NULL, 0);
}
return 0;
}
This way we would then pass "/bin/ls"
|
The biggest difference is we could replace |
codejoncode
left a comment
There was a problem hiding this comment.
Ian for pipe(p) I would check if it is less than 0 else I would proceed. If it is less than zero then you want to fprintf(stdeer, "pipe failed\n); exit(1); else you can now move forward with your forking remember to error check the fork call as well.
No description provided.