Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / examples / APG / Signals / SigAction.cpp
blobd4f092e054fdd3c9c02b0ec51b19f26a901e4278
1 #include "ace/OS_NS_unistd.h"
2 #include "ace/OS_NS_stdlib.h"
3 #include "ace/Log_Msg.h"
4 // Listing 1 code/ch11
5 #include "ace/Signal.h"
7 // Forward declaration.
8 static void register_actions ();
10 int ACE_TMAIN (int, ACE_TCHAR *[])
12 ACE_TRACE ("::main");
14 ::register_actions (); // Register actions to happen.
16 // This will be raised immediately.
17 ACE_OS::kill (ACE_OS::getpid(), SIGUSR2);
19 // This will pend until the first signal is completely
20 // handled and returns, because we masked it out
21 // in the registerAction call.
22 ACE_OS::kill (ACE_OS::getpid (), SIGUSR1);
24 while (ACE_OS::sleep (100) == -1)
26 if (errno == EINTR)
27 continue;
28 else
29 ACE_OS::exit (1);
31 return 0;
33 // Listing 1
34 #if defined (ACE_HAS_SIG_C_FUNC)
35 extern "C" {
36 #endif
37 // Listing 3 code/ch11
38 static void my_sighandler (int signo)
40 ACE_TRACE ("::my_sighandler");
42 ACE_OS::kill (ACE_OS::getpid (), SIGUSR1);
44 if (signo == SIGUSR1)
45 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Signal SIGUSR1\n")));
46 else
47 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Signal SIGUSR2\n")));
49 ACE_OS::sleep (10);
51 #if defined (ACE_HAS_SIG_C_FUNC)
53 #endif
54 // Listing 3
55 // Listing 2 code/ch11
56 static void register_actions ()
58 ACE_TRACE ("::register_actions");
60 ACE_Sig_Action sa (reinterpret_cast <ACE_SignalHandler> (my_sighandler));
62 // Make sure we specify that SIGUSR1 will be masked out
63 // during the signal handler's execution.
64 ACE_Sig_Set ss;
65 ss.sig_add (SIGUSR1);
66 sa.mask (ss);
68 // Register the same handler function for these
69 // two signals.
70 sa.register_action (SIGUSR1);
71 sa.register_action (SIGUSR2);
73 // Listing 2