13 static volatile int run
= 1;
15 static sem_t sem_child
;
23 for (i
= 0; i
< n
; i
++) {
26 memset (&arr
[0], 0, n
* sizeof(int));
30 high_load (void *unused
)
40 do_signal (void *unused
)
43 kill (getpid(), SIGUSR1
);
44 while (sem_wait(&sem
) < 0 && errno
== EINTR
);
50 do_fork (void *unused
)
55 switch ((pid
= fork())) {
64 while (sem_wait(&sem_child
) < 0 && errno
== EINTR
);
72 static void signal_handler(int sig
)
79 static void child_handler(int sig
)
83 sem_post (&sem_child
);
90 pthread_t id1
, id2
, id3
;
96 memset (&act
, 0, sizeof (act
));
97 act
.sa_handler
= signal_handler
;
99 sigemptyset (&act
.sa_mask
);
100 sigaction (SIGUSR1
, &act
, NULL
);
101 act
.sa_handler
= child_handler
;
102 sigaction (SIGCHLD
, &act
, NULL
);
104 printf ("start\n"); fflush(stdout
);
106 sem_init (&sem
, 0, 0);
107 sem_init (&sem_child
, 0, 0);
108 pthread_create(&id1
, NULL
, high_load
, NULL
);
109 pthread_create(&id2
, NULL
, do_signal
, NULL
);
110 #if !defined(__APPLE__)
111 pthread_create(&id3
, NULL
, do_fork
, NULL
);
114 /* sleep does not work !!! */
115 end
= time(NULL
) + 2;
116 while (time(NULL
) < end
) ;
119 pthread_join(id1
, NULL
);
120 pthread_join(id2
, NULL
);
121 #if !defined(__APPLE__)
122 pthread_join(id3
, NULL
);
125 sem_destroy (&sem_child
);
127 printf ("end\n"); fflush(stdout
);
130 sigprocmask (SIG_SETMASK
, &m
, NULL
);
131 if (sigsetjmp (sj
, 0) == 0)
133 sigaddset (&m
, SIGUSR1
);
134 sigprocmask (SIG_SETMASK
, &m
, NULL
);
139 sigprocmask (SIG_SETMASK
, NULL
, &m
);
140 if (!sigismember (&m
, SIGUSR1
))