X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,TW_CP,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org MIME-Version: 1.0 In-Reply-To: References: <4CB9DE15 DOT 8010308 AT cornell DOT edu> <4CB9E9C0 DOT 3000509 AT cornell DOT edu> <20101018183438 DOT GA25878 AT ednor DOT casa DOT cgf DOT cx> <4CBCA2A5 DOT 4010601 AT cornell DOT edu> <20101018201805 DOT GA26254 AT ednor DOT casa DOT cgf DOT cx> <4CBD9DF2 DOT 3090804 AT cornell DOT edu> <20101019141557 DOT GA31784 AT ednor DOT casa DOT cgf DOT cx> <4CBE5F53 DOT 30402 AT cornell DOT edu> <4CBED0C3 DOT 6080001 AT cornell DOT edu> Date: Wed, 20 Oct 2010 20:25:37 +0100 Message-ID: Subject: Re: Sending signals to a subprocess From: Andy Koppe To: cygwin AT cygwin DOT com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: 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 On 20 October 2010 13:20, Andy Koppe wrote: >> Corinna made tcgetpgrp return 0 instead of -1 in some circumstances (see >> http://www.cygwin.com/ml/cygwin-patches/2009-q4/msg00045.html) because s= he >> saw Linux doing that. =C2=A0But when I run Corinna's test on my Linux sy= stem, I >> get -1 where she got 0. =C2=A0So not all Linuxes agree on what tcgetpgrp= should >> do. > > Hmm, Corinna's test calls tcgetpgrp(master) in the parent only before > the child is forked and after it exited, so it's correct to report > that there's no foreground process. > > I wonder which Linux it was that returned 0 in case of failure. I've > tried it on a recent Opensuse, an old Redhat with a 2.6.9 kernel, and > also a Debian with a 2.4 kernel, and got -1 on all of those. Actually I'd only tried my test on all three systems, whereas I'd tried Corinna's only on the old Redhat, where it did print -1 for failure. On the 2.4 system it can't open /dev/ptmx, whereas on the Opensuse with 2.6.34 I do get the results Corinna reported, including 0 on the master side of the pty when enquiring from the parent. (Process 0 is the startup process, so I guess that makes some sense.) To bring my ramblings to some sort of conclusion, here's a slightly amended version of Corinna's test that checks the master side from the parent process before, *during* and after the child process: #define _XOPEN_SOURCE #include #include #include #include #include #include #include #include #include int main () { int master, slave, status; char pts[256]; printf ("parent pid: %d\n", getpid ()); if ((master =3D open ("/dev/ptmx", O_RDWR | O_NOCTTY)) >=3D 0) { int ret; grantpt (master); unlockpt (master); printf ("parent tcgetpgrp master before child: %d\n", tcgetpgrp (mast= er)); strcpy (pts, ptsname (master)); switch (fork ()) { case -1: break; case 0: // child ret =3D setsid (); printf ("child pid: %d (setsid: %d)\n", getpid (), ret); printf ("child tcgetpgrp master before open: %d\n", tcgetpgrp(master)); if ((slave =3D open (pts, O_RDWR)) >=3D 0) { printf ("child tcgetpgrp master after open: %d\n", tcgetpgrp (master)); printf ("child tcgetpgrp slave: %d\n", tcgetpgrp (slave)); close (slave); } sleep(2); break; default:// parent sleep(1); printf ("parent tcgetpgrp master during child: %d\n", tcgetpgrp (master)); wait (&status); printf ("parent tcgetpgrp master after child: %d\n", tcgetpgrp (master)); break; } close (master); return 0; } return 1; } On Cygwin 1.7: parent pid: 5000 parent tcgetpgrp master before child: 0 child pid: 1572 (setsid: 1572) child tcgetpgrp master before open: 0 child tcgetpgrp master after open: 1572 child tcgetpgrp slave: 1572 parent tcgetpgrp master during child: 0 parent tcgetpgrp master after child: 0 On Opensuse with 2.6.34 kernel: parent pid: 13507 parent tcgetpgrp master before child: 0 child pid: 13508 (setsid: 13508) child tcgetpgrp master before open: 0 child tcgetpgrp master after open: 13508 child tcgetpgrp slave: 13508 parent tcgetpgrp master during child: 13508 parent tcgetpgrp master after child: 0 Andy -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple