This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Possible Bug in Pipes with Win95


I am having trouble implementing pipes with win95, namely, the process reading the pipe does not see the EOF when the writing process closes the file.

With plain cygwin32 b18, the program would sometimes blow-up, sometimes hang, and occassionally run correctly.  With the installation of the coolview patches, the error is atleast consistent, the program hangs after all data has been read from the pipe, but never detects the EOF.

Below is a listing of a test program I have been using, the execution never reaches the   "fprintf(stdout, "Child: Found end of Pipe.\n");" in read_from_pipe.  The parent executes normally and hangs on the "waitpid" command.

If anyone has experiences something similar, please let me know.

-Dave Devejian
widsith@panix.com


#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

void
read_from_pipe (int file)
{
  FILE *stream;
  int c;
  stream = fdopen(file, "r");
  fprintf(stdout, "Child: Open Pipe Successful.\n");
  while (!feof(stream)) {
    c = fgetc (stream);
    putchar (c);
  }
  fprintf(stdout, "Child: Found end of Pipe.\n");
  fclose (stream);
  fprintf(stdout, "Child: Closed Pipe.\n");
}
     
/* Write some random text to the pipe. */
     
void
write_to_pipe (int file)
{
  FILE *stream;
  stream = fdopen (file, "w");
  fprintf (stream, "hello, world!\n");
  fprintf (stream, "goodbye, world!\n");
  fclose (stream);
}

int
main (void)
{
  pid_t pid;
  int status;
  int mypipe[2];

  /*  Create the pipe. */
  status = pipe (mypipe);
  if (status) 
    { 
      fprintf (stderr, "Pipe failed.\n"); 
      return EXIT_FAILURE; 
    } 
  
  /* Create the child process. */
  pid = fork ();

  if (pid == (pid_t) 0) 
    { 
      /* This is the child process. */
      read_from_pipe (mypipe[0]); 
      fprintf(stdout, "Child:  Exiting. . . ");
      exit(EXIT_SUCCESS); 
    } 

  else if (pid < (pid_t) 0) 
    { 
      /* The fork failed. */
      fprintf (stderr, "Fork failed.\n"); 
      return EXIT_FAILURE; 
    } 

  else
    { 
      /* This is the parent process. */ 
      write_to_pipe (mypipe[1]);
      if (waitpid (pid, &status, 0) != pid)
	return EXIT_FAILURE;
      else 
	return EXIT_SUCCESS; 
  } 
}


-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]