Detailed description of fcntl functions for file control and fcntl functions for control
Abstract:This article mainly discusses the basic application of the fcntl function for file control. the dup function can copy file descriptors, while the fcntl
Refer to the differences between FCNTL (), LOCKF, flock in LinuxWhat is the difference between these three functions , which are all about locking up a file?First flock and fcntl are system calls, and LOCKF is a library function . LOCKF is actually
I. fcntl Functions
Function: manipulate the file descriptor to change the attributes of an opened file.
Int fcntl (int fd, int cmd,.../* Arg */);
The cmd value can be as follows:
Copy file descriptorF_dupfd (long)
Set/Get file descriptor
Function Description: Manipulate file characteristics According to the file description.File Control function FcntlHeader file:#include #include Function Prototypes:int fcntl (int fd, int cmd);int fcntl (int fd, int cmd, long arg);int fcntl (int fd,
Function Description: describes the features of a file based on its description.File control functionsFcntl -- file control
LibraryStandard C library (libc,-LC)
Synopsis# Include ;Int fcntl (int fd, int cmd );Int fcntl (int fd, int cmd, long Arg
embedded Linux system Programming (ii)--File Descriptor control function fcntl Because the fcntl function is too flexible and complex, the fcntl function is listed separately from the file IO , which is easy to read in detail. The function
1. DUP functionThe 1.1 DUP function is used to copy a file descriptor , and the copied file descriptor can be used normally (see Example 1). The DUP function returns one of the smallest available file descriptors in the current File descriptor table
int fcntl (int fd,int cmd,...)The function Fcntl provides a very rich feature. The main dependencies are the various parameters of CMD:
Copy an existing file descriptor F_dupfd,f_dupfd_cloexec
Gets the flag for the set file descriptor F_
// The lock1.c/* program first creates a file and opens it in a readable way. Then, it adds some content to the file, and then sets two regions in the file, the first region is 10-30 bytes and the shared lock is used. The second region is 40-50
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.