Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <errno.h>
- #include <string.h>
- #include <unistd.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- int main (int argc, char* argv[]) {
- if (argc != 2) perror ("gay");
- int pid,fd[2];
- pipe(fd);
- pid=fork();
- if (pid==0) {
- close(fd[0]);
- dup2(fd[1],1);
- execlp("sort","sort","-n","-r",argv[1],(char*) NULL);
- perror ("no ha mutat");
- }
- pid=fork();
- if (pid==0) {
- close(fd[1]);
- dup2(fd[0],0);
- execlp("head","head","-n","1",argv[1],(char*)NULL);
- perror("no ha mutat");
- }
- close(fd[0]);
- close(fd[1]);
- while(waitpid(-1,NULL,0)>0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement