This is for a homework assignment so I won’t be sharing my code. I’m only allowed to have “pencil down” discussions. I think that’s what he called it, so basically just a discussion. I’m not looking for code experts.
In my program, I fork multiple times and execlp openssl with dgst which returns a MD5 hash(?). I’m using this string to compare multiple files to see if they are identical.
Currently, the only way I have found to get the output from this is to use -out and save it to a file, but doing this over and over doesn’t append the file, it just rewrites the file so doing this is kind of a slow, painful process.
I’m asking if there is a way through exec or openssl that I can write this output string to a pointer that the parent could then access and manipulate from there so I am not writing to a file and reading it via the parent, one process at a time.
Before you
fork, you can usepipeto create a pair of unidirectional file descriptors (one for reading, and one for writing). After youfork, you can usedup2to set the writing end of the pipe for that child process to the output file descriptor and thenexec. Then, when the parent reads from the reading end of the pipe, it will be reading what the child process is writing to itsstdout.Since you are comparing output from multiple children processes, each child should have it’s own pipe.
This is just a mock-up of the calls you need to use. Your code will have to deal with reading from multiple pipes.