Add-Ons & Services

Poco::Process results in hang after launched process killed

A general discussion forum.

Poco::Process results in hang after launched process killed

Postby marlowabnp » 14 Sep 2011, 15:40

A program of mine that uses Poco to launch processes was mysteriously hanging, apparantly randomly. At long last I have been able to reproduce the problem. The code is shown below.

The problem happens if built with or without -g but does not happen when running under the debugger.

I am running on Linux using GCC 4.4.5, using Poco version 1.4.1.

Basically, I create a thread does a launch followed by a wait. In the meantime the main thread kills the pid. This causes the thread to return from the wait but the main thread then hangs on the exit.

struct my_thread
int pid;
boost::thread* the_thread = new boost::thread(&my_thread::run, this);

void run()
std::vector<std::string> no_args;
Poco::ProcessHandle process_handle = Poco::Process::launch("./beta", no_args);
pid = process_handle.id();
int exit_status = process_handle.wait();
std::cout << "run_beta has finished" << std::endl;

int main(int argc, char* argv[])
my_thread t;
std::cout << "kill complete will now exit." << std::endl;
return 0;

This is extremely cut down just to show the problem. My actual app communicates the pid via a concurrent queue object and it cleans up the boost thread object properly, doing the required join. The app is valgrind-clean (i.e no corruption, memory leaks etc). I realise the above app leaks a boost thread and does not synchronise access to the pid properly; that's why the sleep is there. It's a crude kludge to make the app simpler. The "./beta" is it launching a shellscript that goes to sleep for a long time.

An interesting point is that when I replace ./beta with sleep (adjusting the arg vector to specify a large sleep value) the problem mysteriously goes away. So maybe it is somehow connected to launching processes that are shellscripts.


Andrew Marlow
Posts: 89
Joined: 08 Nov 2010, 17:29

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests