Ok changed my code no, looks like this:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main() {
int ret;
int pid, pid2;
int fd1[2];
int fd2[2];
pipe(fd1);
pid = fork();
if (pid == 0) {
dup2(fd1[1], STDOUT_FILENO);
close(fd2[0]);
close(fd1[0]);
close(fd2[1]);
ret = execlp("ps", "ps", "-aux", NULL);
}
else {
pipe(fd2);
pid2 = fork();
if (pid2 == 0) {
dup2(fd1[0], STDIN_FILENO);
dup2(fd2[1], STDOUT_FILENO);
close(fd1[1]);
close(fd2[0]);
ret = execlp("head", "head", "-10", NULL);
}
else {
dup2(fd2[0], STDIN_FILENO);
close(fd1[1]);
close(fd2[0]);
close(fd1[0]);
ret = execlp("sort", "sort", "-n", NULL);
}
}
return 0;
}
But it doesn't work what's my mistake??