delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2003/04/02/21:44:12

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
Message-ID: <20030403024316.13403.qmail@web21205.mail.yahoo.com>
Date: Wed, 2 Apr 2003 18:43:16 -0800 (PST)
From: gavin bowlby <gavin_bowlby AT yahoo DOT com>
Subject: Re: 1.3.20 : getpgid returns pid != -1 when specified pid no longer exists
To: cygwin AT cygwin DOT com, cgf AT redhat DOT com, corinna-cygwin AT cygwin DOT com
MIME-Version: 1.0

>Ok.  In that event, please provide a simple test
case.

Christopher, Corinna:

Thanks for you help on this!

Here's a short program to recreate this problem:

("main.c")
=====================================================
int main(int argc, char *argv[]) {

   int pid, sid, rc;

   if ((pid = fork()) == 0) {
      // child thread
      pid = getppid();
      while(1) {
         rc = sleep(10);
         printf("child is alive...\n");
         if ((sid = getpgid(pid)) == -1) {
            printf("exiting child process...rc=2\n");
            exit(2);
         }
      }
   }
   else {
      // parent thread
      while(1) {
         rc = sleep(10);
         printf("parent is alive...\n");
         // check if our child process has been killed
         if ((sid = getpgid(pid)) == -1)
            exit(3);

         printf("getpgid of child pid:%d returned
pid:%d\n", pid, sid);
      }
   }
}
==========================================
and here are the steps I used to find the problem:

1) bring up Cygwin shell 1
2) gcc main.c <create executable>
3) a.exe <run executable>
4) let program run 10-15 seconds to see output from
    parent and child
5) bring up Cygwin shell 2
6) ps <to see PIDs of parent and child>
7) kill -9 <child PID>
8) observe that parent continues to run, and sees
   the parent's PID reported as the result of the
   getpgid

BTW, the same problem occurs if the parent PID is
killed - the child continues to see that the parent
PID is alive.

The general problem I'm trying to solve here is:

Given a long-lived parent process and a long-lived
child process, I want the parent and child to be able
to detect if the child or parent has died, and if so,
exit.

Thanks again for your kind assistance.

Gavin Bowlby
<gavin_bowlby AT yahoo DOT com>


__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - File online, calculators, forms, and more
http://tax.yahoo.com

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.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