Linux fcntl函数

fcntl函数

读法:file control函数
作用:复制文件描述符、设置/获取文件的状态标志

int fcntl(int fd, int cmd, ... /* arg */ )

fd是文件描述符,cmd是命令(定义的宏),… 表示可变的参数(可有可不有)

man 2 fcntl

DESCRIPTION:
fcntl() performs one of the operations described below on the open file descriptor fd. The operation is determined by cmd.
1、Duplicating a file descriptor 复制文件描述符

  • F_DUPFD (int)
    Duplicate the file descriptor fd using the lowest-numbered available file descriptor greater than or equal to arg. This is different from dup2(2), which uses exactly the file descriptor specified. (dup2复制指定的fd,而F_DUPFD用的是lowerst)On success, the new file descriptor is returned.

  • F_DUPFD_CLOEXEC (int; since Linux 2.6.24)

2、 File descriptor flags 文件描述标志
The following commands manipulate the flags associated with a file descriptor. Currently, only one such flag is defined: FD_CLOEXEC, the close-on-exec flag. If the FD_CLOEXEC bit is set, the file descriptor will automatically be closed during a successful execve(2). (If the execve(2) fails, the file descriptor is left open.) If the FD_CLOEXEC bit is not set, the file descriptor will remain open across an execve(2).

  • F_GETFD (void)

  • F_SETFD (int)

3、 File status flags 文件状态标志
Each open file description has certain associated status flags, initialized by open(2) and pos

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值