|
@@ -9,20 +9,30 @@
|
|
|
|
|
|
void test_handler(int signo)
|
|
|
{
|
|
|
- printf("caught signo: %d\n", signo);
|
|
|
- fflush(stdout);
|
|
|
+ write(1, "caught SIGCHLD\n", 15);
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
|
|
|
int main(void)
|
|
|
{
|
|
|
pid_t mypid;
|
|
|
- int count = 0;
|
|
|
struct sigaction siga;
|
|
|
static sigset_t sigset;
|
|
|
|
|
|
- mypid = getpid();
|
|
|
+
|
|
|
+ sigfillset(&sigset);
|
|
|
+ siga.sa_handler = test_handler;
|
|
|
+ siga.sa_mask = sigset;
|
|
|
+ siga.sa_flags = 0;
|
|
|
+ if (sigaction(SIGCHLD, &siga, (struct sigaction *)NULL) != 0) {
|
|
|
+ fprintf(stderr, "sigaction choked: %s!", strerror(errno));
|
|
|
+ exit(EXIT_FAILURE);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
+
|
|
|
+ mypid = getpid();
|
|
|
if (fork() == 0) {
|
|
|
int i;
|
|
|
|
|
@@ -30,32 +40,20 @@ int main(void)
|
|
|
sleep(2);
|
|
|
kill(mypid, SIGCHLD);
|
|
|
}
|
|
|
- exit(EXIT_SUCCESS);
|
|
|
+ _exit(EXIT_SUCCESS);
|
|
|
}
|
|
|
|
|
|
- sigfillset(&sigset);
|
|
|
-
|
|
|
- siga.sa_handler = test_handler;
|
|
|
- siga.sa_mask = sigset;
|
|
|
- siga.sa_flags = 0;
|
|
|
-
|
|
|
- if (sigaction(SIGCHLD, &siga, (struct sigaction *)NULL) != 0) {
|
|
|
- fprintf(stderr, "sigaction choked: %s!", strerror(errno));
|
|
|
- exit(EXIT_FAILURE);
|
|
|
- }
|
|
|
- printf("waiting for a SIGCHLD\n");
|
|
|
- fflush(stdout);
|
|
|
|
|
|
+
|
|
|
+ write(1, "waiting for a SIGCHLD\n",22);
|
|
|
for(;;) {
|
|
|
sleep(10);
|
|
|
if (waitpid(-1, NULL, WNOHANG | WUNTRACED) > 0)
|
|
|
break;
|
|
|
- printf("after sleep %d\n", ++count);
|
|
|
- fflush(stdout);
|
|
|
+ write(1, "after sleep\n", 12);
|
|
|
}
|
|
|
|
|
|
- printf("after loop\n");
|
|
|
-
|
|
|
+ printf("Bye-bye! All done!\n");
|
|
|
return 0;
|
|
|
}
|
|
|
|