I'm coding an application on a Raspberry Pi/Raspbian in C++. I create a named pipe (FIFO) with mkfifo()
then I start raspiyuv to grab image from my camera. For memory, raspiyuv is the Raspberry Pi command line application that takes still images and save them as YUV file.
I'm using g++ 6.3 and Boost 1.64 with -std=c++17. The FIFO I create is correct in the sense that I can use it from command line. It works as expected.
The bug is that the application raspiyuv I spawn returns immediately with exit code 0.
My code:
void myFunction()
{
// Create the FIFO here with mkfifo(); // Works fine...
boost::filesystem::path lExecPath =
boost::process::search_path( "raspiyuv" ); // returns correct path
boost::process::child lProcess( lExecPath, "-w 2592 -h 1944 -o - -t 0 -y -s >> /var/tmp/myfifo" );
int lPID = lProcess.id(); // Seems to be correct
int lExitCode = lProcess.exit_code(); // Returns immediately with 0
}
The command $ raspiyuv -w 2592 -h 1944 -o - -t 0 -y -s
is correct when I enter it directly to the command line. Also, the redirection to the FIFO works correctly. -w 2592 -h 1944
give the size of the grabbed image, -o -
means output image to stdout, -t 0
means wait forever, -y
means save only the Y channel and -s
means wait for SIGUSR1 to trigger image capture.
When I call it from the command line, the application is idle until I send a SIGUSR1 then it captures an image and streams it to the FIFO then returns idle. That's fine.
When I spawn it by creating the boost::process::child
object, it returns immediately.
Any idea to correct this and allow the boost::process::child
to remain alive as long as my application (parent process) is alive and I don't send a SIGKILL, etc.?
Thanks for your help!