Can anyone tell me why I have an infinite loop when reading from a pipe?
i = 0;
while(i < 10)
{
test_value = read(pipe3[READING], &message, sizeof(struct MESSAGE));
printf("test_value is %d \n", test_value);
//printf("Entering infinite loop \n");
//printf("i is %d \n", i);
//nbytes = read(pipe3[0], array, 45);
//printf("nbytes is %d \n", nbytes);
//log_dat_fp = fopen(argv[2], "a");
if(read(pipe3[READING], &message, sizeof(struct MESSAGE)) != -1)
{
printf("First if \n");
time(¤t_time);
if(message.owner == 1 && (message.instruction == 'r' || message.instruction == 'R'))
{
printf("First if \n");
fprintf(log_dat_fp, "Store Manager at time: %s received message %d %d %c %s", strtok(ctime(¤t_time), "\n"),
message.owner, child_pid2, message.instruction, message.id);
pclose(log_dat_fp);
}
}
else
{
printf("manager can't read from pipe\n");
exit(1);
} // read no good
i++;
log_dat_fp = fopen(argv[2], "a");
printf("Each pass \n");
}