1 /* Using kill for Communication
2 Copyright (C) 1991-2012 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, if not, see <http://www.gnu.org/licenses/>.
21 #include <sys/types.h>
25 /* When a @code{SIGUSR1} signal arrives, set this variable. */
26 volatile sig_atomic_t usr_interrupt
= 0;
29 synch_signal (int sig
)
34 /* The child process executes this function. */
38 /* Perform initialization. */
39 printf ("I'm here!!! My pid is %d.\n", (int) getpid ());
41 /* Let parent know you're done. */
42 kill (getppid (), SIGUSR1
);
44 /* Continue with execution. */
45 puts ("Bye, now....");
52 struct sigaction usr_action
;
56 /* Establish the signal handler. */
57 sigfillset (&block_mask
);
58 usr_action
.sa_handler
= synch_signal
;
59 usr_action
.sa_mask
= block_mask
;
60 usr_action
.sa_flags
= 0;
61 sigaction (SIGUSR1
, &usr_action
, NULL
);
63 /* Create the child process. */
66 child_function (); /* Does not return. */
69 /* Busy wait for the child to send a signal. */
70 while (!usr_interrupt
)
74 /* Now continue execution. */
75 puts ("That's all, folks!");