Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Create two children
- pid_t child1;
- pid_t child2;
- child1 = fork();
- //wait for child1 to finish, then kill child2
- waitpid() ... child1 {
- kill(child2) }
- pid_t waitpid(pid_t pid, int *status, int options);
- pid_t waitpid(pid_t pid, int *statusPtr, int options);
- #include <stdio.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <sys/wait.h>
- int main (){
- int pid;
- int status;
- printf("Parent: %dn", getpid());
- pid = fork();
- if (pid == 0){
- printf("Child %dn", getpid());
- sleep(2);
- exit(EXIT_SUCCESS);
- }
- //Comment from here to...
- //Parent waits proccess pid (child)
- waitpid(pid, &status, 0);
- //Option is 0 since I check it later
- if (WIFSIGNALED(status)){
- printf("Errorn");
- }
- else if (WEXITSTATUS(status)){
- printf("Exited Normallyn");
- }
- //To Here and see the difference
- printf("Parent: %dn", getpid());
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement