读取系统调用从STDIN读取

时间:2012-08-19 13:19:12

标签: c unix operating-system system

从STDIN

获取输入时,Read System调用何时终止

1 个答案:

答案 0 :(得分:2)

这有很多部分。

首先,让我们澄清OS级IO和stdio级IO之间的区别。 read(2)write(2)(POSIX IO)由POSIX指定,并使用文件描述符(从0开始的数字)进行操作; fread(3)fwrite(3)(stdio IO)由ISO C指定并对文件句柄进行操作,例如STDIN,它在POSIX系统上封装文件描述符并添加一些内容(例如输出缓冲) )在他们之上。

因此,read(2)write(2)不会自行缓冲。您在标准输入(文件描述符0 STDIN上看到的缓冲(这是一个抽象)是由终端(或终端仿真)完成的。搜索规范模式以禁用它。

在stdio级别,fwrite(3)(和printf(3)fprintf(3)等等)根据输出连接的内容输出缓冲。

另见:
How to check if a key was pressed in Linux?
Single characters are not printed on the terminal
Does printing to the screen cause a switch to kernel mode and running OS code in Unix?

相关问题