40 #include "blocxx/BLOCXX_config.h" 63 #include "blocxx/WinProcessUtils.hpp" 74 #ifdef BLOCXX_HAVE_UNISTD_H 78 #if defined(sigemptyset) 103 : m_status_available(pid > 0),
270 return ::kill(pid, sig) == 0 ? 0 : errno;
285 struct ZombieReaperPoolCreator
294 class ZombieReaper :
public Runnable 329 :
m_impl(new ChildProcessImpl())
353 :
m_impl(new ChildProcessImpl())
504 if (!killProcess(killTimeout, terminationSelectionFlag))
518 if (!
killWait(sigkillTimeout, SIGKILL,
"SIGKILL", terminationSelectionFlag))
532 float const mult = 1.20;
533 float const max_period = 5000.0;
534 float period = 100.0;
539 period = (std::min)(max_period, period * mult);
554 DWORD rc1 = WaitForSingleObject(pid, 0);
555 if(rc1 == WAIT_FAILED)
562 BOOL rc = GetExitCodeProcess(pid, &exitCode);
576 bool Process::terminateByMessage(
const Timeout& waitTime)
578 DWORD bsmApp = BSM_APPLICATIONS;
579 UINT termMsg = RegisterWindowMessage(TERM_MESSAGE);
580 BOOL bSucceed = BroadcastSystemMessage(BSF_IGNORECURRENTTASK, &bsmApp, termMsg, NULL, NULL);
601 DWORD result = ERROR_SUCCESS;
603 DWORD pId = WinUtils::getProcessIdNT(
m_pid);
606 result = WinUtils::killProcessGroup(pId);
610 result = WinUtils::killProcess(pId);
613 if (result != ERROR_SUCCESS)
632 return GetCurrentProcess();
645 wpid = ::waitpid(pid, &status, WNOHANG | WUNTRACED);
647 }
while (wpid < 0 && errno == EINTR);
673 Format fmt(
"Failed sending %1 to process %2.", signame,
m_pid);
674 char const * msg = fmt.
c_str();
String toString() const
Get a string representation of the status suitable for debugging or logging.
#define BLOCXX_INVALID_HANDLE
bool terminatesWithin(const Timeout &wait_time)
Timeout asAbsoluteTimeout() const
Converts the timer to an absolute timeout.
A TimeoutTimer is used by an algorithm to determine when a timeout has expired.
UnnamedPipeRef in() const
Stdin for the child process.
void loop()
Meant to be called by timeout functions which loop, but don't want to reset the interval.
BLOCXX_COMMON_API Process::Status waitPid(const ProcId &pid)
void repr(int &rep1, int &rep2) const
This String class is an abstract data type that represents as NULL terminated string of characters...
const char * signalName(int sig)
void waitCloseTerm(const Timeout &wait_initial=Timeout::relative(5.0), const Timeout &wait_close=Timeout::relative(10.0), const Timeout &wait_term=Timeout::relative(15.0), ETerminationSelectionFlag terminationSelectionFlag=E_TERMINATE_PROCESS_GROUP)
Waits for the child process to terminate, taking increasingly severe measures to ensure that this hap...
bool expired() const
Indicates whether the last loop time has exceeded the timeout.
bool terminatedSuccessfully() const
BLOCXX_COMMON_API bool shouldUseWaitpidThreadFix()
String lastErrorMsg(bool socketError)
UnnamedPipeRef out() const
Stdout for the child process.
void release()
Releases ownership of the ProcId and UnnamedPipes held by this object.
virtual int kill(ProcId pid, int sig)=0
Sends signal sig to process pid.
Process(UnnamedPipeRef const &in, UnnamedPipeRef const &out, UnnamedPipeRef const &err, ProcId pid)
static Timeout relative(float seconds)
The ThreadPool class is used to coordinate a group of threads.
GlobalString COMPONENT_NAME
bool killWait(const Timeout &wait_time, int sig, char const *signame, ETerminationSelectionFlag terminationSelectionFlag)
ETimeoutType getType() const
virtual Process::Status pollStatus(ProcId pid)=0
virtual ~Process()
If release has been called on this object, does nothing.
A timeout can be absolute, which means that it will happen at the specified DateTime.
There are two methods for creating a thread of execution in the blocxx systems.
IntrusiveReference< ProcessImpl > ProcessImplRef
#define BLOCXX_GLOBAL_STRING_INIT(str)
int getPOSIXwaitpidStatus() const
Get the result from waitpid()
virtual int close()=0
Close the pipe.
The process and any descendent processes which are in the process group will be terminated.
bool signalTerminated() const
#define BLOCXX_THROW(exType, msg)
Throw an exception using FILE and LINE.
Abstract interface for abstracting details of dealing with a process.
#define BLOCXX_DEFINE_EXCEPTION(NAME)
Define a new exception class named <NAME>Exception that derives from Exception.
ETerminationSelectionFlag
float getRelative() const
This class can be used to store a global variable that is lazily initialized in a thread safe manner...
#define BLOCXX_LAZY_GLOBAL_INIT(...)
Statically initialize a LazyGlobal instance.
Process::Status pollStatusImpl(ProcId pid)
UnnamedPipeRef err() const
Stderr for the child process.
This class is the base of all exceptions thrown by BloCxx code.
#define BLOCXX_THROW_ERRNO_MSG(exType, msg)
Throw an exception using FILE, LINE, errno and strerror(errno)
ProcId pid() const
Process ID for the child process.
static void sleep(UInt32 milliSeconds)
Suspend execution of the current thread until the given number of milliSeconds have elapsed...
static const char * TERM_MESSAGE
#define BLOCXX_LOG_DEBUG(logger, message)
Log message to logger with the Debug level.
bool exitTerminated() const