Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fcntl.h>
- #include <errno.h>
- #include <string.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <unistd.h>
- #include <dirent.h>
- #include <pwd.h>
- #include <ctype.h>
- #include <sys/wait.h>
- #include <unistd.h>
- #include <time.h>
- #include <math.h>
- int putere(int a, int b) //a la put b
- {
- for(int i=1; i<=b; i++)
- a=a*a;
- return a;
- }
- int main(int argc, char* argv[])
- {
- int p1[2],p2[2];
- if(pipe(p1)==-1)
- {
- printf("eroare la pipe 1");
- exit(0);
- }
- if(pipe(p2)==-1)
- {
- printf("eroare la pipe 2");
- exit(0);
- }
- pid_t fiu1=fork()
- {
- if(fiu1==-1)
- {
- printf("eroare la primul fiu");
- exit(0);
- }
- else if(fiu1==0)
- {
- close(p1[1]);
- close(p2[0]);
- close(p2[1]);
- int a1, b1;
- read(p1[0],&a1,sizeof(int));
- read(p1[0],&b1,sizeof(int));
- int rezultat=putere(a1,b1);
- close(p1[0]);
- }
- else
- {
- pid_t fiu2=fork()
- if(fiu2==-1)
- {
- printf("eroare la fiul 2");
- exit(0);
- }
- }
- else if(fiu2==0)
- {
- close(p1[0]);
- close(p2[1]);
- close(p1[1]);
- int a2,b2;
- read(p2[0],&a2,sizeof(int));
- read(p2[0],&b2,sizeof(int));
- int rezultat2=putere(a2,b2);
- close(p2[0]);
- }
- else
- {
- close(p1[0]);
- close(p2[0]);
- srand(time(NULL));
- int nr1=rand()%10;
- srand(time(NULL));
- int nr2=rand()%10;
- write(p1[1],&nr1,sizeof(int));
- write(p2[1],&nr2,sizeof(int));
- write(p1[1],&nr2,sizeof(int));
- write(p2[1],&nr1,sizeof(int));
- close(p1[1]);
- close(p2[1]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement