what I am trying to do is pass dynamically load a text file into buffer (in parent) and pass this data to another process (child). then child returns this data back to parent. I have done this much so far. by the way child and parent are in different such parent.cpp and child.cpp Any help please?
string fileName;// File will be opened
char* str=argv[1];
fileSetup(argv[1]);//check if file exists and load into buffer
int pipe_fds[2]; //Define and create pipes
pid_t pid;//child process ID
int read_fd; //pipe_fds[0]
int write_fd;//pipe_fds[1]
int p=pipe (pipe_fds);
read_fd = pipe_fds[0];
write_fd = pipe_fds[1];
pid = fork ();//Fork the child process.
if(pid == -1)//Check if pipe successfully created
{
cerr << "Failed to fork" << endl;
exit(1);
}
if(pid == 0)//Child
{
// Child process closes up input side of pipe
dup2 (write_fd, STDIN_FILENO);
execlp ("./child", "child",str, NULL);//Run child process
close(read_fd);
}
else//Parent
{
}