Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / examples / APG / Processes / Process_Manager_Spawn.cpp
blobf0c427f38481c00862d4869427c520ff3bf22863
1 #include "ace/OS_NS_unistd.h"
2 #include "ace/Log_Msg.h"
3 // Listing 0 code/ch10
4 #include "ace/Process_Manager.h"
6 static const int NCHILDREN = 2;
8 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
10 if (argc > 1) // Running as a child.
12 ACE_OS::sleep (10);
14 else // Running as a parent.
16 // Get the processwide process manager.
17 ACE_Process_Manager* pm = ACE_Process_Manager::instance ();
19 // Specify the options for the new processes
20 // to be spawned.
21 ACE_Process_Options options;
22 options.command_line (ACE_TEXT ("%s a"), argv[0]);
24 // Spawn two child processes.
25 pid_t pids[NCHILDREN];
26 pm->spawn_n (NCHILDREN, options, pids);
28 // Destroy the first child.
29 pm->terminate (pids[0]);
31 // Wait for the child we just terminated.
32 ACE_exitcode status;
33 pm->wait (pids[0], &status);
35 // Get the results of the termination.
37 #if !defined(ACE_WIN32)
38 if (WIFSIGNALED (status) != 0)
39 ACE_DEBUG ((LM_DEBUG,
40 ACE_TEXT ("%d died because of a signal ")
41 ACE_TEXT ("of type %d\n"),
42 pids[0], WTERMSIG (status)));
43 #else
44 ACE_DEBUG
45 ((LM_DEBUG,
46 ACE_TEXT ("The process terminated with exit code %d\n"),
47 status));
48 #endif /*ACE_WIN32*/
50 // Wait for all (only one left) of the
51 // children to exit.
52 pm->wait (0);
55 return 0;
57 // Listing 0