delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2010/10/20/07:22:24

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=0.7 required=5.0 tests=AWL,BAYES_50,SPF_NEUTRAL,T_RP_MATCHES_RCVD
X-Spam-Check-By: sourceware.org
Message-ID: <4CBED0C3.6080001@cornell.edu>
Date: Wed, 20 Oct 2010 07:21:39 -0400
From: Ken Brown <kbrown AT cornell DOT edu>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.9) Gecko/20100915 Thunderbird/3.1.4
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: Sending signals to a subprocess
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> <AANLkTikUc9i0h-g3QHGzqKKRGoJf0-xSPgu6wy1U+zZ=@mail.gmail.com>
In-Reply-To: <AANLkTikUc9i0h-g3QHGzqKKRGoJf0-xSPgu6wy1U+zZ=@mail.gmail.com>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/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

On 10/20/2010 1:09 AM, Andy Koppe wrote:
> On 20 October 2010 04:17, Ken Brown<kbrown AT cornell DOT edu>  wrote:
>> Emacs creates a subprocess that runs an interactive bash shell.  Emacs wants
>> to get the PGID of the foreground process group associated to the tty of
>> this shell, and it does this on Linux via TIOCGPGRP (or equally well
>> tcgetpgrp).  I think it uses the file descriptor of the master of the pty
>> for this purpose.  If you (or some other programmer reading this) could give
>> me the code for setting all this up, I could play with it and try to figure
>> out why I'm seeing a difference between Linux and Cygwin here.  I just don't
>> know how to create a subprocess, give it a terminal, etc.
>
> Here's a test along those lines that does show a difference between
> Linux and Cygwin:
>
> #include<stdio.h>
> #include<pty.h>
>
> int main(void)
> {
>    int pid, fd;
>    pid = forkpty(&fd, 0, 0, 0);
>    if (!pid)
>      sleep(2);
>    else {
>      sleep(1);
>      printf("pid=%i fd=%i pgrp=%i\n", pid, fd, tcgetpgrp(fd));
>    }
> }

Thanks, Andy.  I had no idea how to do this.

> On Linux, where it requires -lutil to link, this gives:
>
> pid=13308 fd=3 tcgetpgrp(fd)=13308

I can confirm this on my Linux system.  I mention this because 
apparently tcgetpgrp isn't the same on all Linux systems.  See below.

> On Cygwin:
>
> pid=268 fd=3 tcgetpgrp(fd)=0

Corinna made tcgetpgrp return 0 instead of -1 in some circumstances (see 
http://www.cygwin.com/ml/cygwin-patches/2009-q4/msg00045.html) because 
she saw Linux doing that.  But when I run Corinna's test on my Linux 
system, I get -1 where she got 0.  So not all Linuxes agree on what 
tcgetpgrp should do.

> Neither of those looks POSIX-compliant to me, because tcgetpgrp should
> return -1 since fd 3 isn't the controlling terminal of the calling
> process, but the Linux behaviour is rather useful. Perhaps they
> decided to apply that restriction only to the slave side?

Ken

--
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

- Raw text -


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