Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , 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: Wed, 2 Apr 2003 22:05:51 -0500 From: Christopher Faylor To: gavin bowlby Cc: cygwin AT cygwin DOT com Subject: Re: 1.3.20 : getpgid returns pid != -1 when specified pid no longer exists Message-ID: <20030403030551.GB7346@redhat.com> Reply-To: cygwin AT cygwin DOT com Mail-Followup-To: gavin bowlby , cygwin AT cygwin DOT com References: <20030403024316 DOT 13403 DOT qmail AT web21205 DOT mail DOT yahoo DOT com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030403024316.13403.qmail@web21205.mail.yahoo.com> User-Agent: Mutt/1.4i On Wed, Apr 02, 2003 at 06:43:16PM -0800, gavin bowlby wrote: >>Ok. In that event, please provide a simple test case. > >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 >3) a.exe >4) let program run 10-15 seconds to see output from > parent and child >5) bring up Cygwin shell 2 >6) ps >7) kill -9 >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. Try it on UNIX/Linux. Same behavior. The pid exists until you wait() for it. Add a 'waitpid (pid, &stat, WNOHANG);' before the parent's getpgid and the loop will terminate on Cygwin or UNIX. cgf -- Please use the resources at cygwin.com rather than sending personal email. Special for spam email harvesters: send email to aaaspam AT sourceware DOT org and be permanently blocked from mailing lists at sources.redhat.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/