delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/02/10/11:31:28

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Date: Tue, 10 Feb 2004 10:30:18 -0600
From: roywestfall AT houston DOT rr DOT com
Subject: Recently changed behavior for daemons
To: cygwin AT cygwin DOT com
Cc: roywestfall AT houston DOT rr DOT com
Reply-to: roywestfall AT houston DOT rr DOT com
Message-id: <175d2217261e.17261e175d22@texas.rr.com>
MIME-version: 1.0
X-Virus-Scanned: Symantec AntiVirus Scan Engine
Note-from-DJ: This may be spam

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/

- Raw text -


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