4
// $Id: //poco/1.2/Foundation/include/Poco/Process.h#1 $
10
// Definition of the Process class.
12
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
15
// Permission is hereby granted, free of charge, to any person or organization
16
// obtaining a copy of the software and accompanying documentation covered by
17
// this license (the "Software") to use, reproduce, display, distribute,
18
// execute, and transmit the Software, and to prepare derivative works of the
19
// Software, and to permit third-parties to whom the Software is furnished to
20
// do so, all subject to the following:
22
// The copyright notices in the Software and this entire statement, including
23
// the above license grant, this restriction and the following disclaimer,
24
// must be included in all copies of the Software, in whole or in part, and
25
// all derivative works of the Software, unless such copies or derivative
26
// works are solely in the form of machine-executable object code generated by
27
// a source language processor.
29
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
32
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
33
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
34
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
35
// DEALINGS IN THE SOFTWARE.
39
#ifndef Foundation_Process_INCLUDED
40
#define Foundation_Process_INCLUDED
43
#include "Poco/Foundation.h"
46
#if defined(POCO_OS_FAMILY_WINDOWS) && defined(POCO_WIN32_UTF8)
47
#include "Poco/Process_WIN32U.h"
48
#elif defined(POCO_OS_FAMILY_WINDOWS)
49
#include "Poco/Process_WIN32.h"
50
#elif defined(POCO_OS_FAMILY_UNIX)
51
#include "Poco/Process_UNIX.h"
53
#include "Poco/Process_VMS.h"
63
class Foundation_API ProcessHandle
64
/// A handle for a process created with Process::launch().
66
/// This handle can be used to determine the process ID of
67
/// the newly created process and it can be used to wait for
68
/// the completion of a process.
71
typedef ProcessImpl::PIDImpl PID;
73
ProcessHandle(const ProcessHandle& handle);
74
/// Creates a ProcessHandle by copying another one.
77
/// Destroys the ProcessHandle.
79
ProcessHandle& operator = (const ProcessHandle& handle);
80
/// Assigns another handle.
83
/// Returns the process ID.
86
/// Waits for the process to terminate
87
/// and returns the exit code of the process.
90
ProcessHandle(ProcessHandleImpl* pImpl);
95
ProcessHandleImpl* _pImpl;
101
class Foundation_API Process: public ProcessImpl
102
/// This class provides methods for working with processes.
106
typedef ArgsImpl Args;
109
/// Returns the process ID of the current process.
111
static void times(long& userTime, long& kernelTime);
112
/// Returns the number of seconds spent by the
113
/// current process in user and kernel mode.
115
static ProcessHandle launch(const std::string& command, const Args& args);
116
/// Creates a new process for the given command and returns
117
/// a ProcessHandle of the new process. The given arguments are
118
/// passed to the command on the command line.
120
static ProcessHandle launch(const std::string& command, const Args& args, Pipe* inPipe, Pipe* outPipe, Pipe* errPipe);
121
/// Creates a new process for the given command and returns
122
/// a ProcessHandle of the new process. The given arguments are
123
/// passed to the command on the command line.
125
/// If inPipe, outPipe or errPipe is non-null, the corresponding
126
/// standard input, standard output or standard error stream
127
/// of the launched process is redirected to the Pipe.
128
/// PipeInputStream or PipeOutputStream can be used to
129
/// send receive data from, or send data to the process.
131
/// Note: the same Pipe can be used for both outPipe and errPipe.
133
/// After a Pipe has been passed as inPipe, only write operations
134
/// are valid. After a Pipe has been passed as outPipe or errPipe,
135
/// only read operations are valid.
137
/// It is forbidden to pass the same pipe as inPipe and outPipe or errPipe.
141
/// Process::Args args;
142
/// ProcessHandle ph(launch("/bin/ps", args, &outPipe, 0, 0));
143
/// PipeInputStream istr(outPipe);
144
/// ... // read output of ps from istr
145
/// int rc = ph.wait();
147
static int wait(const ProcessHandle& handle);
148
/// Waits for the process specified by handle to terminate
149
/// and returns the exit code of the process.
151
static void kill(PID pid);
152
/// Kills the process with the given pid.
154
static void requestTermination(PID pid);
155
/// Requests termination of the process with the give PID.
157
/// On Unix platforms, this will send a SIGINT to the
158
/// process and thus work with arbitrary processes.
160
/// On other platforms, a global event flag
161
/// will be set. Setting the flag will cause
162
/// Util::ServerApplication::waitForTerminationRequest() to
163
/// return. Therefore this will only work with applications
164
/// based on Util::ServerApplication.
171
inline Process::PID Process::id()
173
return ProcessImpl::idImpl();
177
inline void Process::times(long& userTime, long& kernelTime)
179
ProcessImpl::timesImpl(userTime, kernelTime);
186
#endif // Foundation_Process_INCLUDED