1 #include "ace/Log_Msg.h"
2 #include "ace/Process_Manager.h"
3 #include "ace/Reactor.h"
5 static const int NCHILDREN
= 2;
8 class DeathHandler
: public ACE_Event_Handler
11 DeathHandler () : count_(0)
13 ACE_TRACE ("DeathHandler::DeathHandler");
16 virtual int handle_exit (ACE_Process
* process
)
18 ACE_TRACE ("DeathHandler::handle_exit");
22 ACE_TEXT ("Process %d exited with exit code %d\n"),
23 process
->getpid (), process
->return_value ()));
25 if (++count_
== NCHILDREN
)
26 ACE_Reactor::instance ()->end_reactor_event_loop ();
35 // Listing 0 code/ch10
36 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
38 if (argc
> 1) // Running as a child.
41 // Instantiate a process manager with space for
43 ACE_Process_Manager
pm (10, ACE_Reactor::instance ());
45 // Create a process termination handler.
48 // Specify the options for the new processes to be spawned.
49 ACE_Process_Options options
;
50 options
.command_line (ACE_TEXT ("%s a"), argv
[0]);
52 // Spawn two child processes.
53 pid_t pids
[NCHILDREN
];
54 pm
.spawn_n (NCHILDREN
, options
, pids
);
56 // Register handler to be called when these processes exit.
57 for (int i
= 0; i
< NCHILDREN
; i
++)
58 pm
.register_handler (&handler
, pids
[i
]);
60 // Run the reactor event loop waiting for events to occur.
61 ACE_Reactor::instance ()->run_reactor_event_loop ();