forked from sudikrt/assignments
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3_7_sigchild.c
42 lines (38 loc) · 1.05 KB
/
3_7_sigchild.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <signal.h>
#include <stdlib.h>
#include <stdio.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)
{
/* Cleaning child process. */
int status;
wait (&status);
/* Store its exit status in a global variable. */
child_exit_status = status;
}
int main ()
{
pid_t child_pid;
/* Handle SIGCHILD by calling clean_up_child_process. */
struct sigaction sigchld_action;
memset (&sigchld_action, 0, sizeof (sigchld_action));
sigchld_action.sa_handler = &clean_up_child_process;
sigaction (SIGCHLD, &sigchld_action, NULL);
/* Forking Child process. */
child_pid = fork ();
if (child_pid > 0)
{
printf ("hello\n");
sleep(60);
}
else
{
printf ("hello333333333\n");
/* exit (0); */
}
printf ("Status %d\n", child_exit_status);
return 0;
}