不知道这是否完美无缺,但主要的想法就在这里
int fd[2];  /*write(fd[1],buffer,strlen)
            / read(fd[0],buffer2,SIZE)*/
pid_t cpid,savepid;
if(pipe(fd)==-1){
    perror("pipe");
    exit(EXIT_FAILURE);
}
if((cpid=fork())<0){/*  FORK INIT FOR CHILD  */
    printf("\n\tFORK ERROR\n");
    exit(1);
}
if(cpid==0){        /*process CHILD*/
    if((cpid=fork())<0){/*  FORK INIT FOR GRANDCHILD */
        printf("\n\tFORK ERROR\n");
        exit(1);
    }
    if(cpid==0){        /*process GRANDCHILD*/
        close(fd[0]);
        if((write(fd[1],(char*)pid,strlen(final2)))<0){
            perror("\n\tWRITE ERROR");
        }
        /********CODE******/
        close(fd[1]);
    }else{                  /*process CHILD*/
        /********CODE******/
    }
}else{                  /*process PARENT*/
    close(fd[1]);
    if((read(fd[0],(char*)savepid,NN))<0){
        perror("\n\tREAD ERROR");   
    }
    /********CODE******/
    kill(savepid,SIGKILL);
    /*code parent*/
    wait(NULL);
    close(fd[0]);
}