1 #include "ace/Log_Msg.h"
2 #include "ace/Reactor.h"
3 #include "ace/Event_Handler.h"
4 #include "ace/Signal.h"
5 #include "ace/OS_NS_unistd.h"
6 #include "ace/OS_NS_string.h"
8 #if !defined (ACE_LACKS_UNIX_SIGNALS)
10 // Listing 1 code/ch11
11 class MySignalHandler
: public ACE_Event_Handler
14 MySignalHandler () : ACE_Event_Handler()
17 // Listing A code/ch11
18 int handle_signal (int signum
, siginfo_t
* siginfo
= 0, ucontext_t
* = 0)
20 ACE_DEBUG ((LM_INFO
, ACE_TEXT ("Received signal [%S]\n"),
25 ACE_TEXT ("No siginfo_t available for ")
26 ACE_TEXT ("signal [%S]\n"),
31 #if defined (ACE_LINUX)
32 // Listing B code/ch11
34 ACE_TEXT ("errno for this signal is %d [%s]\n"),
36 ACE_OS::strerror (siginfo
->si_errno
)));
38 ACE_TEXT ("signal was sent by process %d")
39 ACE_TEXT (" / user %d\n"),
43 switch (siginfo
->si_code
)
46 ACE_DEBUG ((LM_INFO
, ACE_TEXT ("Timer expiration\n")));
51 ACE_TEXT ("Sent by kill, sigsend or raise\n")));
56 ACE_TEXT ("Sent by kernel\n")));
63 // Listing C code/ch11
67 switch (siginfo
->si_code
)
72 ACE_TEXT ("Divide by zero at %@\n"),
79 ACE_TEXT ("Numeric overflow at %@\n"),
88 // Listing D code/ch11
90 switch (siginfo
->si_code
)
97 // Listing E code/ch11
100 ACE_TEXT ("A child process has exited\n")));
102 ACE_TEXT ("The child consumed %l/%l time\n"),
106 ACE_TEXT ("and exited with value %d\n"),
107 siginfo
->si_status
));
112 #endif /* __linux__ */
118 #endif /* ACE_LACKS_UNIX_SIGNALS */
120 #if !defined (ACE_LACKS_UNIX_SIGNALS)
122 int ACE_TMAIN (int, ACE_TCHAR
*[])
124 #if defined (ACE_LACKS_FORK)
125 //FUZZ: disable check_for_lack_ACE_OS
126 ACE_DEBUG ((LM_DEBUG
,
127 "This example requires fork()\n"));
128 //FUZZ: enable check_for_lack_ACE_OS
130 // Create a child process so that we can test our
131 // ability to handle SIGCHLD
133 // Listing 2 code/ch11
134 ACE_Sig_Set signalSet
;
135 signalSet
.fill_set ();
138 ACE_Reactor::instance ()->register_handler (signalSet
, &h1
);
139 pid_t childPid
= ACE_OS::fork ();
140 if (childPid
== 0) // This is the parent process.
147 ACE_Reactor::instance ()->run_reactor_event_loop ();
150 #endif /* ACE_LACKS_FORK */
158 ACE_TMAIN (int, ACE_TCHAR
*[])
160 ACE_DEBUG ((LM_DEBUG
,
161 "This example does not work on this platform.\n"));
165 #endif /* !ACE_LACKS_UNIX_SIGNALS */