You fork
and then you create the pipe so each process is going to its own set of pipes that don't talk to each other.
Just switch the code around and call pipe
before fork
and you should be good to go.
Also, though it probably won't matter here, get in the habit of reading and writing in a loop. read
& write
are not guaranteed to get nor put all the data you request in one call. Likewise, close your pipes after you done. Closing the write end of the pipe will signal to the reader that the end-of-file has been reached.
while (read(fds[0], read_buffer, sizeof(read_buffer)) > 0)
{
//process bytes read
}