We are trying to read char* data from a pipe given to multiple child processes .
each child writes a char* into a shared pipe, which the parent process reads from.
what we're trying to do is parse the information on a children processes running in xv6.
when parsing a single process, we don't have any trouble, but when parsing a pipe process, which has a recursive call to "runcmd" the following problem accures:
we used the following code in the parent's end:
while(read(p[0],buff,sizeof(buff)) > 0){
printf(1,"\nprocess from pipe in main: " );
printf(1,buff);
printf(1,"\n");
}
and in the children end:
char * name = ecmd->argv[0];
char * data=(char*)malloc(strlen(name)*sizeof(char)+strlen(pidc2)*sizeof(char)+3);
strcpy(data,name);
char* delimiter="#";
strcpy(data+strlen(name),delimiter);
strcpy(data+strlen(name)+strlen(delimiter),pidc2);
strcpy(data+strlen(name)+strlen(delimiter)+strlen(pidc2),"\0");
write(pp[1],data,sizeof(char)*(strlen(data)));
when we run this code with "ls|cat", it will print:
ls#*some_pid*cat#*some_pid*
instead of reading from each child and printing
ls#*some_pid*
cat#*some_pid*
why won't it send them separately?
Aucun commentaire:
Enregistrer un commentaire