#define _POSIX_C_SOURCE 200112L #include #include #include #include #include #include "err.h" int main(int argc, char *argv[]) { int d; switch(fork()) { case -1: FATAL("fork"); break; case 0: // le fils if ((d = open("toto", O_WRONLY|O_TRUNC|O_CREAT, 0666)) == -1) FATAL("open"); close(STDOUT_FILENO); if (dup2(d, STDOUT_FILENO) == -1) FATAL("dup2"); close(d); execlp("ls", "ls", NULL); // NOT REACHED FATAL("exec"); default: // le pere wait(NULL); } return EXIT_SUCCESS; }