| 1 |
////////////////////////////////////////////////////////////////////////////// |
| 2 |
////////////////////////////////////////////////////////////////////////////// |
| 3 |
// |
| 4 |
// copyright : (C) 2014 Eran Ifrah |
| 5 |
// file name : ZombieReaperPOSIX.cpp |
| 6 |
// |
| 7 |
// ------------------------------------------------------------------------- |
| 8 |
// A |
| 9 |
// _____ _ _ _ _ |
| 10 |
// / __ \ | | | | (_) | |
| 11 |
// | / \/ ___ __| | ___| | _| |_ ___ |
| 12 |
// | | / _ \ / _ |/ _ \ | | | __/ _ ) |
| 13 |
// | \__/\ (_) | (_| | __/ |___| | || __/ |
| 14 |
// \____/\___/ \__,_|\___\_____/_|\__\___| |
| 15 |
// |
| 16 |
// F i l e |
| 17 |
// |
| 18 |
// This program is free software; you can redistribute it and/or modify |
| 19 |
// it under the terms of the GNU General Public License as published by |
| 20 |
// the Free Software Foundation; either version 2 of the License, or |
| 21 |
// (at your option) any later version. |
| 22 |
// |
| 23 |
////////////////////////////////////////////////////////////////////////////// |
| 24 |
////////////////////////////////////////////////////////////////////////////// |
| 25 |
|
| 26 |
#include "ZombieReaperPOSIX.h" |
| 27 |
|
| 28 |
#include "event_notifier.h" |
| 29 |
|
| 30 |
#ifndef __WXMSW__ |
| 31 |
|
| 32 |
#include "file_logger.h" |
| 33 |
|
| 34 |
#include <sys/wait.h> |
| 35 |
|
| 36 |
wxDEFINE_EVENT(wxEVT_CL_PROCESS_TERMINATED, wxProcessEvent); |
| 37 |
|
| 38 |
ZombieReaperPOSIX::ZombieReaperPOSIX() |
| 39 |
: wxThread(wxTHREAD_JOINABLE) |
| 40 |
{ |
| 41 |
} |
| 42 |
|
| 43 |
ZombieReaperPOSIX::~ZombieReaperPOSIX() {} |
| 44 |
|
| 45 |
void* ZombieReaperPOSIX::Entry() |
| 46 |
{ |
| 47 |
while(!TestDestroy()) { |
| 48 |
int status(0); |
| 49 |
pid_t pid = ::waitpid((pid_t)-1, &status, WNOHANG); |
| 50 |
if(pid > 0) { |
| 51 |
// Notify about this process termination |
| 52 |
wxProcessEvent event(0, pid, status); |
| 53 |
event.SetEventType(wxEVT_CL_PROCESS_TERMINATED); |
| 54 |
EventNotifier::Get()->AddPendingEvent(event); |
| 55 |
clDEBUG() << "ZombieReaperPOSIX: process" << (int)pid << "exited with status code" << status << clEndl; |
| 56 |
} |
| 57 |
wxThread::Sleep(500); |
| 58 |
} |
| 59 |
|
| 60 |
clDEBUG() << "ZombieReaperPOSIX: going down" << clEndl; |
| 61 |
return NULL; |
| 62 |
} |
| 63 |
|
| 64 |
void ZombieReaperPOSIX::Stop() |
| 65 |
{ |
| 66 |
if(IsAlive()) { |
| 67 |
Delete(NULL, wxTHREAD_WAIT_BLOCK); |
| 68 |
} else { |
| 69 |
Wait(wxTHREAD_WAIT_BLOCK); |
| 70 |
} |
| 71 |
} |
| 72 |
#endif |