I have a PipeLine class for running third-party programs: https://github.com/mikelsv/opensource/blob/master/msvcore/crossplatform/console.cpp#L590 .

To run a third-party program, you need to call Run() , passing in the name of the program. https://github.com/mikelsv/opensource/blob/master/msvcore/crossplatform/console.cpp#L694

The Run() function creates 4 pipes, then, using the fork() call, creates another process in which the specified program is started via system() . It also redirects stdin and company to the parent process.

This code works fine, but periodic “freezes” are seen on select() , https://github.com/mikelsv/opensource/blob/master/msvcore/crossplatform/console.cpp#L814 .

I run / usr / bin / php-cgi, at least a couple of times per minute. About once every half hour, one of the threads hangs on select() . There is no php-cgi in the process list. It seems that the child thread is terminated without closing the pipe, but I do not see how this situation can arise.

Tell me where there may be an error.

    1 answer 1

    Try to protect the process of launching an external task with a semaphore from the moment of creating a pair of sockets (pipes) to the closure of sockets duplicating to a descendant. There is a feeling that while simultaneously running several external processes, there is a possibility of confusion about which of the sockets of the parent process to inherit. As a result, the signal about the closure of the pipe from the side of the child can be lost.