亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区
Chinaunix
標(biāo)題:
發(fā)現(xiàn)close(1)和fclose(stdout)效果并不一樣,為什么?
[打印本頁(yè)]
作者:
centos_71
時(shí)間:
2015-02-02 22:12
標(biāo)題:
發(fā)現(xiàn)close(1)和fclose(stdout)效果并不一樣,為什么?
我寫了一個(gè)小程序:
#include<unistd.h>
#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
int main()
{
int fd=open("/dev/stdout", O_WRONLY);
fclose(stdout);//close(STDOUT_FILENO);
dup(fd);
stdout=fdopen(fd,"w");
printf("haha\n");
return 0;
}
復(fù)制代碼
它什么也不輸出,但是如果我去掉fclose(stdout)改為close(STDOUT_FILENO),那么程序就能運(yùn)行輸出haha
這是為什么呢? man fclose說(shuō)了這個(gè)fclose()內(nèi)部會(huì)調(diào)用close()來(lái)關(guān)閉相應(yīng)的fd,那么和close(1)的效果應(yīng)該一樣才對(duì)啊。
但是在我的centos6上面就是不一樣的運(yùn)行結(jié)果。這是為什么呢?
謝謝
歡迎光臨 Chinaunix (http://www.72891.cn/)
Powered by Discuz! X3.2