Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Pipe commands #4 din setul CV
- ---------------------------------------------------------------------------------
- #fisierul cv1.1.c
- ---------------------------------------------------------------------------------
- #include <unistd.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #include <errno.h>
- int main()
- {
- pid_t pid;
- int p[2];
- if(-1 == pipe(p) )
- {
- fprintf(stderr, "Eroare: nu pot crea un canal anonim, errno=%d\n",errno); perror("Cauza erorii"); exit(1);
- }
- if(-1 == (pid=fork()) )
- {
- perror("Eroare: nu am putut crea un fiu. Cauza erorii"); exit(2);
- }
- if(pid == 0)
- {
- if(-1 == dup2(p[1],1) )
- {
- perror("Eroare: redirectarea iesirii standard in fiu a esuat. Cauza erorii"); exit(3);
- }
- execlp("w", "w", "-h", NULL);
- perror("Eroare la execlp() in fiu. Cauza erorii"); exit(4);
- }
- else
- {
- close(p[1]);
- if(-1 == dup2(p[0],0) )
- {
- perror("Eroare: redirectarea intrarii standard in parinte a esuat. Cauza erorii"); exit(5);
- }
- execl("cv1.2.exe", "cv1.2", NULL);
- perror("Eroare la execl() in parinte. Cauza erorii"); exit(6);
- }
- return 0;
- }
- ----------------------------------------------------------------------
- #fisierul cv1.2.c
- ----------------------------------------------------------------------
- #include <unistd.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #include <errno.h>
- int main()
- {
- pid_t pid;
- int p[2];
- if(-1 == pipe(p) )
- {
- fprintf(stderr, "Eroare: nu pot crea un canal anonim, errno=%d\n",errno); perror("Cauza erorii"); exit(1);
- }
- if(-1 == (pid=fork()) )
- {
- perror("Eroare: nu am putut crea un fiu. Cauza erorii"); exit(2);
- }
- if(pid == 0)
- {
- if(-1 == dup2(p[1],1) )
- {
- perror("Eroare: redirectarea iesirii standard in fiu a esuat. Cauza erorii"); exit(3);
- }
- execlp("tr", "tr", "-s", "\" \"", NULL);
- perror("Eroare la execlp() in fiu. Cauza erorii"); exit(4);
- }
- else
- {
- close(p[1]);
- if(-1 == dup2(p[0],0) )
- {
- perror("Eroare: redirectarea intrarii standard in parinte a esuat. Cauza erorii"); exit(5);
- }
- execl("cv1.3.exe","cv1.3",NULL);
- perror("Eroare la execl() in parinte. Cauza erorii"); exit(6);
- }
- return 0;
- }
- ----------------------------------------------------------------------
- #fisierul cv1.3.c
- ----------------------------------------------------------------------
- #include <unistd.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #include <errno.h>
- int main()
- {
- pid_t pid;
- int p[2];
- if(-1 == pipe(p) )
- {
- fprintf(stderr, "Eroare: nu pot crea un canal anonim, errno=%d\n",errno); perror("Cauza erorii"); exit(1);
- }
- if(-1 == (pid=fork()) )
- {
- perror("Eroare: nu am putut crea un fiu. Cauza erorii"); exit(2);
- }
- if(pid == 0)
- {
- if(-1 == dup2(p[1],1) )
- {
- perror("Eroare: redirectarea iesirii standard in fiu a esuat. Cauza erorii"); exit(3);
- }
- execlp("cut", "cut", "-d\" \"", "-f1,8", NULL);
- perror("Eroare la execlp() in fiu. Cauza erorii"); exit(4);
- }
- else
- {
- close(p[1]);
- if(-1 == dup2(p[0],0) )
- {
- perror("Eroare: redirectarea intrarii standard in parinte a esuat. Cauza erorii"); exit(5);
- }
- execlp("sort","sort","-t", "\" \"", "-k","1", NULL);
- perror("Eroare la execlp() in parinte. Cauza erorii"); exit(6);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement