2
我在网上搜索了这个话题,并且遇到了这个解释,但我无法理解它的背后。代码和解释如下..dup()和close()系统调用之间的关系是什么?
#include <unistd.h>
...
int pfd;
...
close(1);
dup(pfd);
close(pfd); //** LINE F **//
...
/*The example above closes standard output for the current
processes,re-assigns standard output to go to the file referenced by pfd,
and closes the original file descriptor to clean up.*/
LINE F做什么?为什么它至关重要?
对。在Windows下,关闭描述符是严格要求的,因为用于处理重复的OS函数,并且关闭描述符可确保句柄也关闭并释放资源。 –