What is fork and what is pipe?
What could be some scenarios explaining why their use is necessary?
What are the differences between fork and pipe in C?
Can we use them in C++?
I need to know this is because I want to implement a program in C++ which can access live video input, convert its format and write it to a file.
What would be the best approach for this?
I have used x264 for this. So far I have implemented the part of conversion on a file format.
Now I have to implement it on a live stream.
Is it a good idea to use pipes? Capture video in another process and feed it to the other?
A pipe is a mechanism for interprocess communication. Data written to the pipe by one process can be read by another process. The primitive for creating a pipe is the pipe function (from header file unistd.h in the C POSIX library). This creates both the reading and writing ends of the pipe.
It is not very useful for a single process to use a pipe to talk to itself. In typical use, a process creates a pipe just before it
forksone or more child processes. The pipe is then used for communication either between the parent or child processes, or between two sibling processes.A familiar example of this kind of communication can be seen in all operating system shells. When you type a command at the shell, it will spawn the executable represented by that command with a call to
fork. A pipe is opened to the new child process and its output is read and printed by the shell.This page has a full example of the
forkandpipefunctions. For your convenience, the code is reproduced below:Just like other C functions you can use both
forkandpipein C++.