关于dup2引发的文件缓冲区的思考
linuxc吧
全部回复
仅看楼主
level 1
百思不得姐呀
2013年07月02日 12点07分 1
level 1
我写了个这样的例子:
#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
int main(void)
{
int fd;
fd = open("txt",O_RDWR | O_CREAT | O_TRUNC );
if(fd == -1)
{
perror("open");
return -1;
}
printf("******");
dup2(fd,STDOUT_FILENO);
printf("######\n");
close(1);
return 0;
}
终端无输出,txt里“******######”,为什么呢
2013年07月02日 12点07分 3
printf是带缓冲的啊,换行或close时才会写入,so。。。。。
2013年09月28日 08点09分
level 7
表示不懂。。
-----低调奢华V880,喂自己袋盐╭(╯ε╰)╮
2014年01月20日 16点01分 4
1