How can a Unix program display output on screen even when stdout and stderr are redirected?

后端 未结 3 1598
半阙折子戏
半阙折子戏 2021-01-07 21:51

I was running a program (valgrind, actually) on my Ubuntu machine, and had redirected both stdout and stderr to different files. I was surprised to see a short message appea

3条回答
  •  再見小時候
    2021-01-07 22:12

    The message is most probably from GCC's stack protector feature or from glib itself. If it's from GCC, it is output using the fail() function, which directly opens /dev/tty:

    fd = open (_PATH_TTY, O_WRONLY);
    

    _PATH_TTY is not really standard, but SingleUnix actually demands that /dev/tty exists.

提交回复
热议问题