I am working on a project that has multiple C++ executables that communicate using named pipes. The main application (App1) spawns the rest of the applications. When spawning, it closes STDIN for the children using:
close(STDIN_FILENO);
And it redirects STDOUT and STDERR to other files that are specific to the child processes. This makes it so that the output from App1 is only from App1 and none of the children. It also allows App1 to accept input from STDIN and not let it get captured by the child processes.
One of the child processes is a Qt application. When spawned, it is using as much CPU as it can, slowing my computer considerably. If I do not close STDIN for the child processes, this behavior stops (but the children capture STDIN instead of the main process, which I don’t want).
Why does this happen and how can I prevent the Qt applications from using all the CPU cycles?
I think I figured out what the issue was while fixing another issue I was having. I was closing the
STDINfile descriptor before redirecting theSTDERRandSTDOUTfile descriptors. This was messing up the indexes that are used when I usedfreopen()to redirect them.I moved the
close()ofSTDINto after the redirection, and don’t seem to have the problem anymore.