How do I recover my pipe on my Parent's Death?

Frank Merrow frank at odetics.com
Wed May 22 07:34:31 AEST 1991


Hi,

I am attempting to monitor a number of file descriptors for input using
select().  Below I have included a piece of my code.  Actually things
work pretty good, EXCEPT for some reason when one of the processes
(my parent in this case) dies.  (If it matters the file descriptors
were originally created with pipe() and dup2()ed to STDIN and STDOUT
after the fork().)

At any rate once the parent dies, select() immediately releases, but
the ioctl() shows "nothing" in the pipe so I go back to the select()
which immediately releases and so on.  What do I need to do to
detect/clear the condition.  Note that I tried setting O_NDELAY
expecting the read() to return -1 and some kind of a nice error code.
However it just returns zero and the condition STILL is not cleared.

Frank
frank at odetics.com or uunet!odetics!frank

typedef
   struct
      {
      int fd;
      void (*routine)();
      } FD_LIST;

. . .

num_fd_list        = 1;
fd_list[0].fd      = STDIN;
fd_list[0].routine = xfp_request;

/* Other fd's to be added at a later time.				*/

/* Ok, I loop waiting for input and then processing it.			*/

for (keep_going=TRUE;keep_going;)
   {
   if (select(numfds,&readfds,NULL,NULL,NULL) < 1)
      fatal("select() error in main(xfs)");
   PRINT_TRACE("select() released");
   for (i=0;i < num_fd_list;i++)
      {
      if (ioctl(fd_list[i].fd,FIONREAD,&nbytes) != 0)
	 fatal("ioctl() error in main(xfs)");
      if (nbytes > 0)
	 (*fd_list[i].routine) (i);
      }
   }



More information about the Comp.unix.questions mailing list