This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Sending signals to a subprocess

On 20 October 2010 04:17, Ken Brown <> 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)
  else {
    printf("pid=%i fd=%i pgrp=%i\n", pid, fd, tcgetpgrp(fd));

On Linux, where it requires -lutil to link, this gives:

pid=13308 fd=3 tcgetpgrp(fd)=13308

On Cygwin:

pid=268 fd=3 tcgetpgrp(fd)=0

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?


Problem reports:
Unsubscribe info:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]