Note to Floyd

June 29th, 2012 - 12:30 pm ET by root | Report spam
Once again I want to thank your for your efforts.

I made a change to your pipe/socket program that
now seems to work for either line-by-line or
sort child programs.

Here is the change:
/* Write to child process */

// fpout = fdopen(fd_child_inp[1], "w");
// setvbuf(fpout, (char *) NULL, _IONBF, 0);
while ( sizen > 0 ) {
int chunk = 1000;
if (sizen < 1000) {
chunk = sizen;
}
// fwrite(buffer, 1, chunk, fpout);
write(1,buffer,chunk); // CHANGE HERE
buffer += chunk;
sizen -= chunk;
}
close(fd_child_inp[1]);
close(fd_child_out[0]);
sleep(1);
kill(c1pid, SIGKILL);
exit(EXIT_SUCCESS);

I eliminated the fdopen() and did direct write.
email Follow the discussionReplies 1 replyReplies Make a reply

Replies

#1 root
June 29th, 2012 - 12:48 pm ET | Report spam
root wrote:
Once again I want to thank your for your efforts.

I made a change to your pipe/socket program that
now seems to work for either line-by-line or
sort child programs.

Here is the change:
/* Write to child process */

// fpout = fdopen(fd_child_inp[1], "w");
// setvbuf(fpout, (char *) NULL, _IONBF, 0);
while ( sizen > 0 ) {
int chunk = 1000;
if (sizen < 1000) {
chunk = sizen;
}
// fwrite(buffer, 1, chunk, fpout);
write(1,buffer,chunk); // CHANGE HERE
buffer += chunk;
sizen -= chunk;
}
close(fd_child_inp[1]);
close(fd_child_out[0]);
sleep(1);
kill(c1pid, SIGKILL);
exit(EXIT_SUCCESS);

I eliminated the fdopen() and did direct write.




My mistake Floyd. When I send the output to sort
I got something back, but it wasn't sorted. That
means the reading back isn't coming from the child
program. I think one of the pipes is left open
for your fdopen() call.

When I change the read-back to use read instead
fgets I get blocked.

Similar topics