boostorg / boostorg/process

Zombie process on Linux running non existing process

Open
#216 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
145
Forks
151
PR merge metrics
No merged PRs in 30d

Description

Hello,

A program like this:

```cpp
#include
#include
#include
#include
#include
#include
#include

void runProcess(const std::string& arg_command)
{
try
{
boost::process::ipstream out, err; // reading pipe-stream
boost::process::child process(arg_command, boost::process::std_out > out, boost::process::std_err > err);
process.wait(); // wait for the process to exit
int result = process.exit_code();

std::stringstream output, error;
out >> output.rdbuf();
err >> error.rdbuf();
if(result == 0)
{
std::cout << output.str() << "\n";
}
else
{
std::cout << "Error output: " << output.str() << "\n" << error.str() << "\n";
}
}
catch(const std::system_error& e)
{
std::string err_msg = std::string("Exception: ") + e.what();

std::cerr << err_msg << "\n";
};
}

int main()
{
for (int i=0; i<50; i++)
{
runProcess("/usr/bin/does_not_exist");
}

std::cout << "Boost version: " << BOOST_LIB_VERSION << "\n";
std::cout << "Open another shell and check for zombie process..." << "\n";
int val = 0;
std::cin >> val;
}
```

I got 50 zombie processes.

Tested on Ubuntu 20.04, g++ 9.3, boost versions 1.71 and 1.75 exhibit this behavior.

More importantly, boost 1.72 running on funky old ARMv5 based embedded Linuxes, our bread and butter, same thing.
Poor machines eventually got "Too many files opened" after months of being online.

Q: ok, so the executable does not exist, exception handler is invoked, that is understood, but how is it that child process is now zombied? There should not be any child process in the first place as file simply does not exist. Is `fork()` performed before checking if executable exists?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.