Advertisement
Guest User

Untitled

a guest
Dec 17th, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #include <errno.h>
  2. #include <string.h>
  3. #include <unistd.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <sys/types.h>
  7. #include <sys/stat.h>
  8. #include <fcntl.h>
  9.  
  10. int main (int argc, char* argv[]) {
  11. if (argc != 2) perror ("gay");
  12. int pid,fd[2];
  13. pipe(fd);
  14. pid=fork();
  15. if (pid==0) {
  16. close(fd[0]);
  17. dup2(fd[1],1);
  18. execlp("sort","sort","-n","-r",argv[1],(char*) NULL);
  19. perror ("no ha mutat");
  20. }
  21. pid=fork();
  22. if (pid==0) {
  23. close(fd[1]);
  24. dup2(fd[0],0);
  25. execlp("head","head","-n","1",argv[1],(char*)NULL);
  26. perror("no ha mutat");
  27. }
  28. close(fd[0]);
  29. close(fd[1]);
  30. while(waitpid(-1,NULL,0)>0);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement