28 lines
553 B
C
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;
|
||
|
}
|