There are two separate things going on.
ls: >: No such file or directory
can be fixed by settingargumnts[index]=NULL
before callingexecvp
.ls
is seeing the> outputfile
as additional filenames it should list. TheNULL
to terminate the argument list will take care of that.Error: Failure to wait for child. : Interrupted system call
: something is happening while waiting. Interrupted system calls (EINTR
) are often not a problem and can be restarted with no ill effects. I found the following suggestion here to replace the single call towaitpid
:
"A typical code sequence would be:
while((pid = waitpid(,,)) == -1) { switch (errno) { case EINTR: continue; default: printf(stderr, ...) break; }} ... rest of normal waitpid-hanling goes here ...
Also, you'll probably have to install a signalhandler for at least SIGCHLD . "
Also, I note you have not redirected stderr, which may cause interactions between parent and child. One other question - did you hit control-C? If so, see here.
Also, WUNTRACED
may or may not be something you want to specify, depending on whether you're handling terminal signals. See the manpage for waitpid(2), e.g., here. Perhaps 0
, or WEXITED
?