delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1997/10/27/19:02:42

From: widsith AT panix DOT com (David Devejian)
Subject: Possible Bug in Pipes with Win95
27 Oct 1997 19:02:42 -0800 :
Message-ID: <01BCE30F.58C2B060.cygnus.gnu-win32@widsith.dialup.access.net>
Mime-Version: 1.0
To: "'gnu-win32 AT cygnus DOT com'" <gnu-win32 AT cygnus DOT com>

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 AT panix DOT 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 AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019