1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
/* -*- C++ -*- */
// $Id$
// ============================================================================
//
// = LIBRARY
// ace
//
// = FILENAME
// Process.h
//
// = AUTHOR
// Tim Harrison <harrison@cs.wustl.edu>
//
// ============================================================================
#if !defined (ACE_PROCESS_H)
#define ACE_PROCESS_H
#include "ace/OS.h"
#include "ace/ARGV.h"
#include "ace/ACE.h"
#include "ace/Mem_Map.h"
#include "ace/Svc_Handler.h"
#include "ace/Synch.h"
#include "ace/Acceptor.h"
#include "ace/SOCK_Acceptor.h"
class ACE_Export ACE_Process
// = TITLE
// A Portable encapsulation for creating new processes and
// allows assignment of STDIN, STDOUT, and STDERR of the new
// process.
//
// = DESCRIPTION
// On UNIX, ACE_Process uses fork and exec. On Win32, it uses
// CreateProcess. Since we can set the standard handles, we can
// mimic UNIX pipes on Win32 by building chains of processes.
// This class should be used instead ACE_OS::fork_exec. I'm
// implementing the functionality that I need as I go, instead of
// trying to build an all encompassing process abstraction. If
// anyone needs more functionality, please feel free to add it and
// send us the updates. We'll put it in ACE.
{
public:
ACE_Process (void);
// Default construction.
ACE_Process (char *argv[],
ACE_HANDLE std_in,
ACE_HANDLE std_out = ACE_INVALID_HANDLE,
ACE_HANDLE std_err = ACE_INVALID_HANDLE);
// Set the standard handles of the new process to the respective
// handles and start the new process. -argv- must be specified. It
// should be of the following form: argv = {
// "c:\full\path\to\foo.exe", "-a", "arg1", "etc", 0 } Returns the
// new process id on success, -1 on failure. If you want to affect
// a subset of the handles, make sure to set the others to
// ACE_INVALID_HANDLE.
~ACE_Process (void);
// Death incarnate.
int set_handles (ACE_HANDLE std_in,
ACE_HANDLE std_out = ACE_INVALID_HANDLE,
ACE_HANDLE std_err = ACE_INVALID_HANDLE);
// Set the standard handles of the new process to the respective
// handles. If you want to affect a subset of the handles, make
// sure to set the others to ACE_INVALID_HANDLE. Returns 0 on
// success, -1 on failure.
int start (char *argv[]);
// Start the new process. -argv- must be specified. It should be
// of the following form: argv = { "c:\full\path\to\foo.exe", "-a",
// "arg1", "etc", 0 } Returns the new process id on success, -1 on
// failure.
int wait (void);
// Wait for the process we just created to exit.
int kill (int signum = SIGINT);
// Send the process a signal.
pid_t getpid (void);
// Return the pid of the new process.
private:
#if defined (ACE_WIN32)
PROCESS_INFORMATION process_info_;
STARTUPINFO startup_info_;
int set_handles_called_;
// Is 1 if stdhandles was called.
#else /* ACE_WIN32 */
ACE_HANDLE stdin_;
ACE_HANDLE stdout_;
ACE_HANDLE stderr_;
pid_t child_id_;
#endif /* ACE_WIN32 */
};
#if defined (__ACE_INLINE__)
#include "ace/Process.i"
#endif /* __ACE_INLINE__ */
#endif /* ACE_PROCESS_H */
|