Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <unistd.h>
- #include <stdio.h>
- #include <stdlib.h>
- int main(void)
- {
- int fd_in[2];
- int fd_out[2];
- pid_t pid;
- if ((pipe(fd_in) < 0) && (pipe(fd_out) < 0)) {
- return EXIT_FAILURE;
- }
- if ((pid = fork()) < 0) {
- return EXIT_FAILURE;
- } else if (pid != 0) { /* father */
- close(fd_in[1]);
- close(fd_out[0]);
- dup2(fd_in[0], STDIN_FILENO);
- dup2(fd_out[1], STDOUT_FILENO);
- execlp("bash", "bash", (char *)0);
- } else { /* son */
- FILE *file = fdopen(fd_out[0], "w");
- int c;
- close(fd_in[0]);
- close(fd_out[1]);
- write(fd_in[1], "ls\n", 3);
- while( (c=fgetc(file) != EOF)) {
- putchar(c);
- }
- }
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement