13 if (pipe(pipefd
) == -1) {
14 perror("Pipe creation failure\n");
21 perror("fork failure\n");
23 } else if (cpid
== 0) {
25 dup2(pipefd
[1], STDOUT_FILENO
);
26 execl("/bin/ls", "ls", (char*)NULL
);
31 printf("[%d] REDIRECTION: \n", getpid());
32 //determine the pipe size to avoid this kind of code
33 while (read(pipefd
[0], &tmpbuf
, 1) > 0) {
34 write(STDOUT_FILENO
, &tmpbuf
, 1);