Unix 中的管道手柄有多近?(fclose() of pclose()).
How close pipe handle in unix? (fclose() of pclose())?
如果我以这种方式在 unix 中创建管道:
int fds[] = {0, 0};
pipe(fds);
然后以这种方式从fds[0]
进行FILE *
:
FILE *pipe_read = fdopen(fds[0], "rt");
那么我应该如何关闭这个文件(pipe_read
(?
-
fclose(pipe_read)
-
pclose(pipe_read)
-
close(fileno(pipe_read))
fdopen
返回一个FILE*
,所以你应该fclose
它。这也将关闭基础文件描述符。
pclose
调用用于关闭使用 popen
创建的句柄,该函数用于运行命令并使用管道连接到它。
close
调用将关闭基础文件描述符,但不幸的是,在文件句柄有机会刷新其数据之前 - 换句话说,您可能会丢失数据。
你应该使用 fclose(pipe_read(。
close(( 关闭内核中的文件描述符。这还不够,因为文件指针不是免费的。所以你应该在pipe_read上使用 fclose((,这也将负责关闭文件描述符。
相关文章:
- pclose() 不会给我进程退出代码
- 从popen()读取的输出是否在pclose()之前完成
- 有没有办法关闭文件? fclose 不能很好地工作
- 尽管文件指针正确,但在fclose()期间的segfault
- 做一个popen(),将文件*指针放入fstream中,pclose()呢?
- 在先前关闭的文件句柄上的 fclose() 上出现双重释放错误
- fclose()函数速度较慢
- Valgrind 在 fclose() 处检测到内存泄漏
- pclose() 返回管道的终止状态是否在所有平台上都向左移动了 8 位?
- To ::close() or to ::fclose()?
- cstdio fopen和fclose在osx上无法正常工作
- ***检测到glibc***..:free():无效的下一个大小(正常):..***fclose();之后;
- 如果机器立即崩溃,那么fflush()在将数据保存到磁盘方面是否与fclose()一样好?
- Invalid free() / delete / delete[] / realloc() for fclose()?
- from where pclose gets pid
- std::fclose()有一个非常奇怪的问题
- 执行命令并获得输出:popen和pclose undefined
- 如果调用 fclose(0),则关闭标准
- Unix 中的管道手柄有多近?(fclose() of pclose()).
- 程序在fclose()时崩溃