什么是FD_CLOEXEC的fcntl()标志呢? [英] What does the FD_CLOEXEC fcntl() flag do?

查看:191
本文介绍了什么是FD_CLOEXEC的fcntl()标志呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

像这样:

if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {
...

虽然我读过男人的fcntl ,我想不出它做什么。

推荐答案

有设置的近距离上的exec 的标志文件描述符,这将导致文件描述符被自动(和原子)关时任 EXEC - 家庭功能得逞。

It sets the close-on-exec flag for the file descriptor, which causes the file descriptor to be automatically (and atomically) closed when any of the exec-family functions succeed.

它还测试返回值,看是否操作失败,这是相当无用的,如果文件描述符是有效的,因为不存在的条件下该操作应在有效的文件描述符失败。

It also tests the return value to see if the operation failed, which is rather useless if the file descriptor is valid, since there is no condition under which this operation should fail on a valid file descriptor.

这篇关于什么是FD_CLOEXEC的fcntl()标志呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆