Subject: Recently changed behavior for daemons
From: [email-masked]
To: [email-masked]
Cc: [email-masked]
Date: Tue, 10 Feb 2004 10:30:18 -0600

I recently upgraded to version 1.5.7-1

Since then, when I run a daemon (i.e. a program that forks, closes file descriptors, chdirs to /, and calls setsid) from a cygwin (non-X) command shell, I am unable to close the cygwin window.  I've tried doing the standard daemon things, and calling the daemon() function, both behave the same.

Below is some sample code to demonstrate, using either method, pass any command line argument to call daemon().

This program simply sleeps for 2 minutes then exits.  If I run it, then exit bash, my window doesn't close.  Forcing the window to close terminates the program.

This behavior has changed since the upgrade.

Roy Westfall
roywestfall<AT>houston<DOT>rr<DOT>com

#include <unistd.h>
#include <fcntl.h>

int main(int ac, char* av[])
{
  int i = 0;

  if (ac > 1)
  {
      daemon(0,0);
  }
  else
  {
    if (fork())
      return 0;
    for (i = getdtablesize()-1; i >= 0; i--)
      close(i);
    open("/dev/null",O_RDONLY);
    dup(open("/dev/null",O_WRONLY));
    chdir("/");
    setsid();
  }

  sleep(120);

  return 0;
}

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/