缓冲区:printf("hello world")
printf打印的数据并不会立即写入到标准输入文件中,而是先将数据写入到一块缓冲区中,等待缓冲区写满或者是手动刷新缓冲区fflush(stdout),才会将数据一次写入到文件中;
fflush(stdout);
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
int main(){
printf("printf");
fprintf(stdout,"%s","frintf");
fwrite("fwriten",1,6,stdout);
write(1,"write",5);
sleep(2);
return 0;
12 }
库函数 | 系统调用接口 |
exit() | _exit() |
退出会刷新缓冲区 | 退出不会刷新缓冲区 |
exit是库函数,封装的有FILE*的结构体,其中分封装的有缓冲区,所以退出就会自动调用刷新缓冲区的功能 | 系统调用接口是不存在文件指针,也就不存在缓存,就更不用说是刷新缓存了 |