1 #include "ace/OS_NS_unistd.h"
2 #include "ace/Log_Msg.h"
3 #include "ace/Signal.h"
4 #include "ace/Sig_Handler.h"
7 class MySignalHandler
: public ACE_Event_Handler
10 MySignalHandler (int signum
) : signum_(signum
)
13 virtual ~MySignalHandler()
16 virtual int handle_signal (int signum
, siginfo_t
* = 0, ucontext_t
* = 0)
18 ACE_TRACE ("MySignalHandler::handle_signal");
20 // Make sure the right handler was called back.
21 ACE_ASSERT (signum
== this->signum_
);
23 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("%S occurred\n"), signum
));
31 // Listing 2 code/ch11
32 int ACE_TMAIN (int, ACE_TCHAR
*[])
34 MySignalHandler
h1 (SIGUSR1
), h2 (SIGUSR2
);
35 ACE_Sig_Handler handler
;
36 handler
.register_handler (SIGUSR1
, &h1
);
37 handler
.register_handler (SIGUSR2
, &h2
);
39 ACE_OS::kill (ACE_OS::getpid (), SIGUSR1
);
40 ACE_OS::kill (ACE_OS::getpid (), SIGUSR2
);
43 while ((time
= ACE_OS::sleep (time
)) == -1)
49 ACE_ERROR_RETURN ((LM_ERROR
,
51 ACE_TEXT ("sleep")), -1);