Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
585 B
2
Indexable
Never
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <sys/wait.h>

int main(int argc, char *argv[])
{
    int fd[2];

    if (pipe(fd) == -1)
    {
        perror("error");
        return 0;
    }

    int id = fork();

    if (id == 0)
    {
        printf("je suis fils\n");

        dup2(fd[1], 1);
        close(fd[0]);
        close(fd[1]);

        execlp("ls", "ls", "-l", argv[1], NULL);
    }

    wait(NULL);
    printf("je suis pere\n");
    dup2(fd[0], 0);
    close(fd[0]);
    close(fd[1]);

    execlp("grep", "grep", argv[2], NULL);
}