#fork() execl() and pipe() need help please.

10 messages · Page 1 of 1 (latest)

honest sphinx
#

Ok, so I'm supposed to Create a child process, send data to that child, have the child output the data, and wait on the child to finish.
Basically the parent process will read the data from the input file, and write it to the pipe.
The child process will read from the pipe, and write to the outputfile. Thing is I'm being provided with 3 classes. FileReader, FileWriter, and PipeMaker.
Here is my code: ``` std::list<EntryInfo> theList;
FileReader reader;
reader.readEntries(theList, Util::inputFilename, true);
FileWriter writer(theList);
writer.writeFile(Util::outputFilename);

pid_t pid;
PipeMaker(myPipe[2]);
pid = fork ();
if (pid < 0){/** fork failed. **/
    fprintf (stderr, "Fork failed.\n");
    exit(EXIT_FAILURE);

}else if (pid == 0){/** Child process. **/
    PipeMaker close(myPipe[1]);
    PipeMaker setUpToRead(myPipe[0]);
    execl("./Part2_Template","W");
    writer.writeFile(Util::outputFilename);

    exit(EXIT_SUCCESS);

} else if(pid > 0){
    /** Parent process. **/
    PipeMaker close(myPipe[0]);
    PipeMaker setUpToWrite(myPipe[1]);
    writer.writeFile(setUpToWrite);
    wait(NULL);


}```  Any help is appreciated, also I can provide the code for the 3 classes that I'm using if needed.
tight tangleBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.

thorny falcon
#

exec replaces the current process

honest sphinx
thorny falcon
#

not the parent process

#

only the child

honest sphinx
#

A side note as well, when I do writer.writeFile(setUpToWrite); I get this error. "No matching constructor for initialization of 'FileWriter'" what does that mean?

proud dirge
#

#1013104018739974194 is not #1013107104678162544 btw

honest sphinx
#

!solved