Hi !!! I have a difficulty with a recent task. I have a very little programming experience and although I do not want someone to solve my homework but the code I wrote looks bad and doesn't work.
I understand how each function work s but have a major difficulty compose them together to a functioning code.
So I would be very thankful if someone who understands C could take a look at the task. Here it is:
I have to write popen() and pclose() functions following the steps: creating a pipe (with pipe(2)) and a child process (with fork(2)). Then associate child process one end of the pipe ("r" or "w") with stdin or stdout, respectively, (with dup2(2)). Afterwards the child process executes the specified command (with execl(3) or execv(3)). Use the shell (sh(1)) similar to the original popen(3) to execute that command. At last the main function has to construct a FILE * from a filedescriptor of the pipe using the fdopen(3) library function.
On pclose(), the calling process waits (waitpid(2)) for the termination of the child process. To ease the implementation, it is sufficient to support at most one pipe at a time. Guarantee that a program cannot call popen() two (or more) times without appropriate and sufficient pclose() in between.
Export all necessary entities (e.g., extern declarations of the two functions) in a corresponding header file.