poll()/select() on a tty fd in a backgrounded process raises SIGTTIN

Jon Turney jon.turney@dronecode.org.uk
Mon Jul 25 10:15:00 GMT 2016

Consider the following:

$ cat sigttin-test.c
#include <unistd.h>
#include <poll.h>

// gcc sigttin-test.c -o sigttin-test
// ./sigttin-test &

int main()
     // poll stdin
     struct pollfd fds;
     fds.fd = STDIN_FILENO;
     fds.events = POLLIN;
     return poll (&fds, 1, 0);

$ gcc sigttin-test.c -o sigttin-test

on cygwin:

$ ./sigttin-test &
[1] 6120

[1]+  Stopped                 ./sigttin-test

$ jobs -l
[1]+  6120 Stopped (tty input)     ./sigttin-test

on linux:

$ ./sigttin-test &
[1] 2779

My reading seems to indicate that SIGTTIN should be raised when read() 
is made on a tty in a backgrounded process, not when it's polled, but 
looking at the Cygwin source code, it's been this way since the earliest 
versions in git...

This test case is reduced from a problem seen with gdb, since commit 
0b333c5e, where gdb stops with SIGTTIN when the inferior is started.

More information about the Cygwin-developers mailing list