1//
2// Process_UNIX.h
3//
4// Library: Foundation
5// Package: Processes
6// Module: Process
7//
8// Definition of the ProcessImpl class for Unix.
9//
10// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
11// and Contributors.
12//
13// SPDX-License-Identifier: BSL-1.0
14//
15
16
17#ifndef Foundation_Process_UNIX_INCLUDED
18#define Foundation_Process_UNIX_INCLUDED
19
20
21#include "Poco/Foundation.h"
22#include "Poco/Event.h"
23#include "Poco/Mutex.h"
24#include "Poco/Optional.h"
25#include "Poco/RefCountedObject.h"
26#include <unistd.h>
27#include <vector>
28#include <map>
29
30
31namespace Poco {
32
33
34class Pipe;
35
36
37class Foundation_API ProcessHandleImpl: public RefCountedObject
38{
39public:
40 ProcessHandleImpl(pid_t pid);
41 ~ProcessHandleImpl();
42
43 pid_t id() const;
44 int wait() const;
45 int wait(int options) const;
46
47private:
48 const pid_t _pid;
49 mutable FastMutex _mutex;
50 mutable Event _event;
51 mutable Optional<int> _status;
52};
53
54
55class Foundation_API ProcessImpl
56{
57public:
58 typedef pid_t PIDImpl;
59 typedef std::vector<std::string> ArgsImpl;
60 typedef std::map<std::string, std::string> EnvImpl;
61
62 static PIDImpl idImpl();
63 static void timesImpl(long& userTime, long& kernelTime);
64 static ProcessHandleImpl* launchImpl(
65 const std::string& command,
66 const ArgsImpl& args,
67 const std::string& initialDirectory,
68 Pipe* inPipe,
69 Pipe* outPipe,
70 Pipe* errPipe,
71 const EnvImpl& env);
72 static void killImpl(ProcessHandleImpl& handle);
73 static void killImpl(PIDImpl pid);
74 static bool isRunningImpl(const ProcessHandleImpl& handle);
75 static bool isRunningImpl(PIDImpl pid);
76 static void requestTerminationImpl(PIDImpl pid);
77
78private:
79 static ProcessHandleImpl* launchByForkExecImpl(
80 const std::string& command,
81 const ArgsImpl& args,
82 const std::string& initialDirectory,
83 Pipe* inPipe,
84 Pipe* outPipe,
85 Pipe* errPipe,
86 const EnvImpl& env);
87};
88
89
90} // namespace Poco
91
92
93#endif // Foundation_Process_UNIX_INCLUDED
94