An assignment in my Operating Systems class requires me to build a binary process tree by recursively calling exec on the same program. The goal is to split some arbitrary task
Besides the issue mentioned by Jonathon Reinhart, most probably the call to execv()
fails.
To test this modify these lines
execvp("two_way_pipes", argv2);
_exit(0);
to be
...
#include
...
execvp("two_way_pipes", argv2); /* On sucess exec*() functions never return. */
perror("execvp() failed); /* Getting here means execvp() failed. */
_exit(errno);
Expect to receive
execvp() failed: No such file or directory
To fix this change
execvp("two_way_pipes", argv2);
to be
execvp("./two_way_pipes", argv2);
Also if the child was not exec*()
ed then this line
read(PARENT_READ, buff, 4); // should read "test" which was written by the child to stdout
fails and in turn buff
is not initialised and therefore this line
fprintf(stderr, "in parent | message received: %s\n", buff);
provokes undefined behaviour.
To fix this at least properly initialise buff
by changing
char buff[5];
to be
char buff[5] = "";