Andy Koppe
Thu Oct 8 12:15:00 GMT 2009

2009/10/8 Corinna Vinschen <>:
> On Oct  8 07:34, Andy Koppe wrote:
>> I'm having trouble with this change:
>>         * (fhandler_termios::tcgetpgrp): Only return
>>         valid pgid if tty is controlling tty.  Set errno to ENOTTY and
>>         return -1 otherwise.
>> Mintty uses the following call to create its pty:
>>   openpty (&parent_fd, &child_fd, 0, 0, winp)
>> It then forks a child process which calls login_tty(child_fd) and
>> execs the shell or other command. Meanwhile, the parent mintty process
>> retains the child_fd, so that it can find out what the current
>> foreground process of the pty is, using tcgetpgrp(child_fd).
>> /proc/<id>/cwd then allows it to find the current working directory of
>> the foreground process.
>> This is used for a new feature in mintty-0.5: Ctrl+clicking on a file
>> to open it via cygstart, whereby the current working directory of the
>> foreground process is needed for relative paths. This worked fine up
>> to 1.7.0-62, but due to the change above it no longer works on
>> cygwin-cvs.
>> Is it really necessary to restrict tcgetpgrp() in that way? Is there
>> any other way to find the current foreground process of a terminal?
> STC?

Here you go. Prints a process ID on 1.7.0-62, but -1 on the latest snapshot.

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <pty.h>

int main(void) {
  int parent_fd, child_fd;
  openpty(&parent_fd, &child_fd, 0, 0, 0);
  if (!fork()) {
    // child process

  // parent process
  printf("%i\n", tcgetpgrp(child_fd));

More information about the Cygwin-developers mailing list