Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int estado, res, resposta, n;
- char palavra[30], buf[3];
- int p[2], pr[2];
- //CRIAR PIPES
- if(pipe(p) == -1 )
- fprintf(stderr,"ERROR CREATING PIPE1!\n");
- if(pipe(pr)== -1)
- fprintf(stderr,"ERROR CREATING PIPE2!\n");
- res = fork();
- if( res < 0 ){
- fprintf(stderr,"\n[ERROR] fork failed!\n");
- return -1;
- }
- if( res == 0 ){ //Filho
- // RDIR INPUT & OUTPUT
- close(0); dup(p[0]);//dup2( p[0], 0);
- close( p[0] );
- close( p[1] );
- close(1); dup(pr[1]);//dup2( pr[1], 1);
- close( pr[0] );
- close( pr[1] );
- if (execl("verificador", "verificador",s.filename,NULL)==-1)
- perror("EXECL Falhou");
- exit(-1);
- }
- //PAI
- close(p[0]);
- close(pr[1]);
- do{
- printf("Palavra: ");
- fflush(stdout);
- fgets(palavra,30,stdin);
- write(p[1], palavra, strlen(palavra));
- }while( strcmp(palavra,"##MSGEND##\n")!=0);
- n=read( pr[0], buf, sizeof(buf));
- buf[n-1]='\0';
- resposta = atoi(buf);
- printf("\nBad Words = %d\n",resposta);
- close(p[1]);
- wait(&estado);
- close( pr[0]);
- return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement