public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: gavin bowlby <gavin_bowlby@yahoo.com>
To: cygwin@cygwin.com, cgf@redhat.com, corinna-cygwin@cygwin.com
Subject: Re: 1.3.20 : getpgid returns pid != -1 when specified pid no longer exists
Date: Thu, 03 Apr 2003 03:00:00 -0000	[thread overview]
Message-ID: <20030403024316.13403.qmail@web21205.mail.yahoo.com> (raw)

>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@yahoo.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/

WARNING: multiple messages have this Message-ID
From: gavin bowlby <gavin_bowlby@yahoo.com>
To: cygwin@cygwin.com, cgf@redhat.com, corinna-cygwin@cygwin.com
Subject: Re: 1.3.20 : getpgid returns pid != -1 when specified pid no longer exists
Date: Thu, 03 Apr 2003 03:05:00 -0000	[thread overview]
Message-ID: <20030403024316.13403.qmail@web21205.mail.yahoo.com> (raw)
Message-ID: <20030403030500.UUGhBcV_utsqqE7CndDRpe7Bo01i8uASs8cPRdbgYmI@z> (raw)

>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@yahoo.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/

             reply	other threads:[~2003-04-03  2:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-03  3:00 gavin bowlby [this message]
2003-04-03  3:05 ` gavin bowlby
2003-04-03  3:19 ` Christopher Faylor
  -- strict thread matches above, loose matches on Subject: below --
2003-04-02 20:20 gavin bowlby
2003-04-02 20:23 ` gavin bowlby
2003-04-02 23:24 ` Christopher Faylor
2003-04-02  3:06 gavin bowlby
2003-04-02  9:30 ` Corinna Vinschen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030403024316.13403.qmail@web21205.mail.yahoo.com \
    --to=gavin_bowlby@yahoo.com \
    --cc=cgf@redhat.com \
    --cc=corinna-cygwin@cygwin.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).