Change sigTTOU/TTIN to IGNORE by default
Malcolm Wallace
Malcolm.Wallace at cs.york.ac.uk
Mon Jan 15 09:58:30 EST 2001
> But we're not changing any of the terminal flags, simply setting
> the same ones again.
> I'm totally stumped! Any ideas, anyone?
According to the manual page,
tcgetattr() ... This function may be invoked
from a background process; however, the terminal
attributes may be subsequently changed by a foreground
process.
In other words, the attributes belong to the *terminal*, not to the
process.
Modifying your C prog a little to print the flag values, and also to
ensure that the TOSTOP flag is unset:
int main(void) {
struct termios tio;
if (tcgetattr(1, &tio) < 0) { exit(1); }
printf("0x%x\n",tio.c_lflag);
tio.c_lflag &= ~TOSTOP;
printf("0x%x\n",tio.c_lflag);
if (tcsetattr(1, TCSANOW, &tio) < 0) { exit(1); }
printf("0x%x\n",tio.c_lflag);
printf("hello world\n");
exit(0);
}
The output of ./a.out is
0x8a1b
0x8a1b
0x8a1b
hello world
and ./aout & is
0x8a11
0x8a11
[pid] Suspended.
Hence, we can see that the TOSTOP flag is not being changed. It is
correctly 'off' all the way through.
But if you actually set the flag using
tio.c_lflag |= TOSTOP;
instead, you will see the output change. With ./a.out & it becomes
0x8a11
0x8b11
[pid] Suspended.
Note the flag is now set correctly, and with *another* invocation of
./a.out & immediately following, you see just:
[pid] Suspended.
Now, not even the debugging output is shown, because the previous
run of the program set the attribute TOSTOP on the terminal.
So it seems that there is possibly a feature/bug in the C library
such that calling tcsetattr() always suspends a backgrounded process,
regardless of the setting of TOSTOP. As yet, I haven't been able to
find a workaround. :-(
Regards,
Malcolm
More information about the Glasgow-haskell-bugs
mailing list