亚洲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è)小程序:

  1. #include<unistd.h>
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include<sys/types.h>
  5. #include<sys/stat.h>
  6. #include<fcntl.h>
  7. int main()
  8. {
  9.     int fd=open("/dev/stdout", O_WRONLY);
  10.     fclose(stdout);//close(STDOUT_FILENO);
  11.     dup(fd);
  12.     stdout=fdopen(fd,"w");
  13.     printf("haha\n");
  14.     return 0;
  15. }
復(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