Difference between FILE * “/dev/stdout” and stdout

独自空忆成欢 提交于 2019-12-05 00:26:09

Both of the streams (stdout and output) are buffered. Nothing actually gets written until they are flushed. Since you are not explicitly flushing them, nor arranging for them to be automatically flushed, they are only being auto-flushed when they are closed.

You are also not explicitly closing them, so they're being closed (and flushed) by the standard library's on_exit hooks. And as William Pursell correctly pointed out, the order in which the buffered I/O streams are closed is not specified.

Look at fflush(3), fclose(3), and setbuf(3) manual pages for more information on controlling when and how your output gets flushed.

/dev/stdout is not the same as /proc/self/fd/0 . In fact, if you have not enough priviledges, you won't be able to write to /dev/stdout as /dev/stdout is not any standard character device in Linux and any attempt to fopen it with the "w" option will try to create an actual regular file on that directory. The character device you are looking for is /dev/tty

In C language, stdout is an initialized global variable of type FILE * which points to the standard output file, that is, the file whose descriptor is 1. stdout only exists in the C namespace and doesn't relate to any actual file named "stdout"

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!