Jump to content
nhamii_02

Erro com Pipes

Recommended Posts

nhamii_02

Boa noite a todos :)

Alguém me sabe dizer porque é que isto não funciona?

int fd[2];
if(pipe(fd)==-1){perror("demo");exit(1);}
if (pid == -1) {perror("demo"); exit(1);}

else
    if (pid==0)
{
dup2(fd[1],1);
    printf("son\n");
    int a = execlp(programa,programa,argumento,NULL);
    perror("demo");
    sleep(1);
}
else
{
    printf("pai\n");
    while((d=read(1,buffer,1000))>0) {
        buffer[d] = '\0';
        printf("<<<<%s\n",buffer);
    waitpid(pid, &status, 0);
    }
}

Quero obter do filho para o pai o resultado do execlp!

Antes de mais , obrigada!

Edited by pmg
GeSHi

Share this post


Link to post
Share on other sites
brunoais

Aonde é que está o fork()?


"[Os jovens da actual geração]não lêem porque não envolve um telecomando que dê para mirar e atirar, não falam porque a trapalhice é rainha e o calão é rei" autor: thoga31

Life is a genetically transmitted disease, induced by sex, with death rate of 100%.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.