BUT2/SCR/SCR2/TP05/ex2.c
2023-10-23 13:23:36 +02:00

28 lines
553 B
C

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int main() {
char *command1[] = {"ls","ls", "-l", NULL};
char *command2[] = {"wc","wc", "-l", NULL};
int p[2];
pipe(p);
pid_t pid = fork();
if (pid == 0) {
close(p[1]);
dup2(p[0], STDIN_FILENO);
execvp(command2[0], command2+1);
exit(-1);
}
else{
close(p[0]);
dup2(p[1], STDOUT_FILENO);
execvp(command1[0], command1+1);
exit(-1);
}
return 0;
}