poco/Foundation/include/Poco/Process_UNIX.h

91 lines
1.8 KiB
C
Raw Normal View History

2012-04-29 20:52:25 +02:00
//
// Process_UNIX.h
//
// Library: Foundation
// Package: Processes
// Module: Process
//
// Definition of the ProcessImpl class for Unix.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
2012-04-29 20:52:25 +02:00
//
#ifndef Foundation_Process_UNIX_INCLUDED
#define Foundation_Process_UNIX_INCLUDED
#include "Poco/Foundation.h"
#include "Poco/RefCountedObject.h"
#include <unistd.h>
#include <vector>
#include <map>
Add ProcessRunner and PIDFile (#4225) * feat(Foundation): PIDFile and ProcessRunner #4064 * feat(Thread): optional signal blocking on POSIX #2978 * fix(ProcessRunner):remove logger, code enhancement #4225 * feat(Foundation): add PIDFile and ProcessRunner Tests #4064 * fix(Foundation): failing ProcessRunner Test #4064 * fix(PIDFile): remove append argument #4064 * remove Windows TODO from ProcessRunner #4064 * feat(ProcessRunnerTest): add line to checkTimeout #4064 * fix(ProcessRunner): add done flag to run() #4064 * fix(ProcessRunnerTest): add missing pidFile argument #4064 * chore(ProcessRunner): remove comments #4064 * fix(ProcessRunner): add runCount flag #4064 * fix(test): SharedLibrary and Class tests paths * fix(ProcessRunner): thread sanitizer reported data races #4064 * fix(build): pass env var to testrunner #4064 * chore(PIDFile): remove ; in comments #4064 * feat(ProcessRunner): add Win argument format #4064 * fix(Tests): add ProcessRunnerTest to vcxproj #4064 * fix(Tests): change path to TestApp #4064 * feat(Tests): windows processrunner tests #4064 * fix(Tests): duplicate ProcessRunnerTest in TestSuite vcxproj #4064 * fix(CodeQL): sw declaration hides variable #4064 * fix test binaries path for cmake * fix(Build): missing include/PIDFile.h buildWin #4064 * fix(Build): add PocoFoundation depend in buildWin #4064 * feat(ProcessRunner): test process launching multiple threads #2976 --------- Co-authored-by: Pavle <pavle@debian-gnu-linux-11.localdomain> Co-authored-by: Alex Fabijanic <alex@pocoproject.org>
2023-11-24 20:22:01 +01:00
#include <atomic>
2012-04-29 20:52:25 +02:00
namespace Poco {
class Pipe;
class Foundation_API ProcessHandleImpl: public RefCountedObject
{
public:
ProcessHandleImpl(pid_t pid);
~ProcessHandleImpl();
2012-04-29 20:52:25 +02:00
pid_t id() const;
int wait() const;
int tryWait() const;
2012-04-29 20:52:25 +02:00
private:
Add ProcessRunner and PIDFile (#4225) * feat(Foundation): PIDFile and ProcessRunner #4064 * feat(Thread): optional signal blocking on POSIX #2978 * fix(ProcessRunner):remove logger, code enhancement #4225 * feat(Foundation): add PIDFile and ProcessRunner Tests #4064 * fix(Foundation): failing ProcessRunner Test #4064 * fix(PIDFile): remove append argument #4064 * remove Windows TODO from ProcessRunner #4064 * feat(ProcessRunnerTest): add line to checkTimeout #4064 * fix(ProcessRunner): add done flag to run() #4064 * fix(ProcessRunnerTest): add missing pidFile argument #4064 * chore(ProcessRunner): remove comments #4064 * fix(ProcessRunner): add runCount flag #4064 * fix(test): SharedLibrary and Class tests paths * fix(ProcessRunner): thread sanitizer reported data races #4064 * fix(build): pass env var to testrunner #4064 * chore(PIDFile): remove ; in comments #4064 * feat(ProcessRunner): add Win argument format #4064 * fix(Tests): add ProcessRunnerTest to vcxproj #4064 * fix(Tests): change path to TestApp #4064 * feat(Tests): windows processrunner tests #4064 * fix(Tests): duplicate ProcessRunnerTest in TestSuite vcxproj #4064 * fix(CodeQL): sw declaration hides variable #4064 * fix test binaries path for cmake * fix(Build): missing include/PIDFile.h buildWin #4064 * fix(Build): add PocoFoundation depend in buildWin #4064 * feat(ProcessRunner): test process launching multiple threads #2976 --------- Co-authored-by: Pavle <pavle@debian-gnu-linux-11.localdomain> Co-authored-by: Alex Fabijanic <alex@pocoproject.org>
2023-11-24 20:22:01 +01:00
std::atomic<pid_t> _pid;
2012-04-29 20:52:25 +02:00
};
class Foundation_API ProcessImpl
{
public:
typedef pid_t PIDImpl;
typedef std::vector<std::string> ArgsImpl;
typedef std::map<std::string, std::string> EnvImpl;
2012-04-29 20:52:25 +02:00
static PIDImpl idImpl();
static void timesImpl(long& userTime, long& kernelTime);
static ProcessHandleImpl* launchImpl(
const std::string& command,
const ArgsImpl& args,
2012-04-29 20:52:25 +02:00
const std::string& initialDirectory,
Pipe* inPipe,
Pipe* outPipe,
2012-04-29 20:52:25 +02:00
Pipe* errPipe,
const EnvImpl& env,
int options = 0);
static void killImpl(ProcessHandleImpl& handle);
2012-04-29 20:52:25 +02:00
static void killImpl(PIDImpl pid);
2014-08-11 08:10:48 +02:00
static bool isRunningImpl(const ProcessHandleImpl& handle);
static bool isRunningImpl(PIDImpl pid);
2012-04-29 20:52:25 +02:00
static void requestTerminationImpl(PIDImpl pid);
private:
static ProcessHandleImpl* launchByForkExecImpl(
const std::string& command,
const ArgsImpl& args,
2012-04-29 20:52:25 +02:00
const std::string& initialDirectory,
Pipe* inPipe,
Pipe* outPipe,
2012-04-29 20:52:25 +02:00
Pipe* errPipe,
const EnvImpl& env,
int options = 0);
2012-04-29 20:52:25 +02:00
};
} // namespace Poco
#endif // Foundation_Process_UNIX_INCLUDED