Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <unistd.h>
- #include <signal.h>
- #include <string.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- sig_atomic_t child_exit_status;
- void clean_up_child_process(int signal_number)
- {
- int status;
- wait(&status);
- child_exit_status = status;
- }
- int main()
- {
- struct sigaction sigchld_action;
- memset(&sigchld_action, 0, sizeof(sigchld_action));
- sigchld_action.sa_handler = &clean_up_child_process;
- sigaction(SIGCHLD, &sigchld_action, NULL);
- pid_t child_pid = fork();
- if (child_pid > 0) {
- printf("Parent process, normal executionn");
- sleep(60);
- printf("After sleepn");
- } else {
- printf("Childn");
- }
- return 0;
- }
- Parent process, normal execution
- Child
- After sleep
Add Comment
Please, Sign In to add comment