{806 Bytes \atop 19:13}  {exec.c \atop 18.11.1999}

#include <stdio.h> #include <sys/wait.h> #include <fcntl.h> #include <unistd.h>

pid t find(int *out,int *err,char *argv[ ])  find

{ int pout[2]; int perr[2];

pid t pid;  10

int res;

if (pipe(pout) < 0)

return 0; if (pipe(perr) < 0)

return 0; if ((pid=fork())< 0)

{ close(pout[0]);

close(pout[1]);  20

close(perr[0]); close(perr[1]); return(0);

} else if (pid !=0)

{ close(pout[1]); close(perr[1]); *out=pout[0];

*err=perr[0];  30

return(pid); }

/*Le fils*/ close(pout[0]); close(perr[0]); dup2(pout[1],STDOUT FILENO); dup2(perr[1],STDERR FILENO); close(pout[1]); close(perr[1]);

res=execvp("find",argv);  40

/* execvp ne retourne jamais */ close(STDOUT FILENO); close(STDERR FILENO); exit(res);

}

void closefind(int out, int err)  closefind

{ close(out);

close(err);  50

}

\overline{1}