speed up the wait loop by sleeping 5 ms before reaping status instead of failing and sleeping 1 S
This commit is contained in:
parent
3e0ae1ccab
commit
677d278fda
@ -27,6 +27,7 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -101,6 +102,13 @@ void ExecCmd::putenv(const string &ea)
|
|||||||
{
|
{
|
||||||
m_env.push_back(ea);
|
m_env.push_back(ea);
|
||||||
}
|
}
|
||||||
|
static void msleep(int millis)
|
||||||
|
{
|
||||||
|
struct timespec spec;
|
||||||
|
spec.tv_sec = millis / 1000;
|
||||||
|
spec.tv_nsec = (millis % 1000) * 1000000;
|
||||||
|
nanosleep(&spec, 0);
|
||||||
|
}
|
||||||
|
|
||||||
/** A resource manager to ensure that execcmd cleans up if an exception is
|
/** A resource manager to ensure that execcmd cleans up if an exception is
|
||||||
* raised in the callback, or at different places on errors occurring
|
* raised in the callback, or at different places on errors occurring
|
||||||
@ -134,11 +142,11 @@ public:
|
|||||||
int ret = killpg(grp, SIGTERM);
|
int ret = killpg(grp, SIGTERM);
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
|
msleep(i == 0 ? 5 : (i == 1 ? 100 : 2000));
|
||||||
int status;
|
int status;
|
||||||
(void)waitpid(m_parent->m_pid, &status, WNOHANG);
|
(void)waitpid(m_parent->m_pid, &status, WNOHANG);
|
||||||
if (kill(m_parent->m_pid, 0) != 0)
|
if (kill(m_parent->m_pid, 0) != 0)
|
||||||
break;
|
break;
|
||||||
sleep(1);
|
|
||||||
if (i == 2) {
|
if (i == 2) {
|
||||||
LOGDEB(("ExecCmd: killpg(%d, SIGKILL)\n", grp));
|
LOGDEB(("ExecCmd: killpg(%d, SIGKILL)\n", grp));
|
||||||
killpg(grp, SIGKILL);
|
killpg(grp, SIGKILL);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user