/**
- * \file forkedcall.C
+ * \file forkedcall.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
#include <config.h>
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
#include "forkedcall.h"
#include "forkedcontr.h"
#include "lstrings.h"
using std::strerror;
#endif
+namespace lyx {
+namespace support {
+
namespace {
if (secs > 0) {
new Murder(secs, pid);
} else if (pid != 0) {
- lyx::kill(pid, SIGKILL);
+ lyx::support::kill(pid, SIGKILL);
}
}
void kill()
{
if (pid_ != 0) {
- lyx::kill(pid_, SIGKILL);
+ lyx::support::kill(pid_, SIGKILL);
}
lyxerr << "Killed " << pid_ << std::endl;
delete this;
// Wait for child process to finish.
-int ForkedProcess::runBlocking()
+int ForkedProcess::runBlocking()
{
retval_ = 0;
pid_ = generateChild();
return retval_;
}
+
+bool ForkedProcess::running() const
+{
+ if (!pid())
+ return false;
+
+ // Un-UNIX like, but we don't have much use for
+ // knowing if a zombie exists, so just reap it first.
+ int waitstatus;
+ waitpid(pid(), &waitstatus, WNOHANG);
+
+ // Racy of course, but it will do.
+ if (::kill(pid(), 0) && errno == ESRCH)
+ return false;
+ return true;
+}
+
+
void ForkedProcess::kill(int tol)
{
- lyxerr << "ForkedProcess::kill(" << tol << ")" << std::endl;
+ lyxerr << "ForkedProcess::kill(" << tol << ')' << endl;
if (pid() == 0) {
lyxerr << "Can't kill non-existent process!" << endl;
return;
Murder::killItDead(0, pid());
} else {
- int ret = lyx::kill(pid(), SIGHUP);
+ int ret = lyx::support::kill(pid(), SIGHUP);
// The process is already dead if wait_for_death is false
bool const wait_for_death = (ret == 0 && errno != ESRCH);
return cpid;
}
+
+} // namespace support
+} // namespace lyx