Lien0000342014-08-23
UNIX provides two functions DUP and dup2 for copying an existing file descriptor.
# Include
Int DUP (INT filedes );
Int dup2 (INT filedes, int filedes2 );
Returned value: If successful, a new file descriptor is returned.
This article was reproduced from: http://blog.csdn.net/tennysonsky/article/details/45870459DUP () and dup2 () are two very useful system calls that are used to copy the descriptor of a file so that the new file descriptor also identifies the file
I. Files in Linux
There are four types of files: common files, directory files, link files, and device files.
1. Common files
Is the most commonly used file, including text files, shell scripts, binary executable and various types of data.
Ls-LH
DUP Function: Copy file descriptorRelated header files: # include Function expression: int DUP (INT filedes );Parameter description: The DUP function parameter filedes indicates the file descriptor of the file to be copied.Return Value Description:
1. File descriptor in the kernel data structureBefore I go into specific dup/dup2, I think it's necessary to look at the file descriptor's pattern in the kernel. During the existence of a process, some files will be opened, which will return some
the role of DUP and dup2DUP and dup2 are also two very useful calls that are used to copy the descriptor of a file. They are often used to redirect stdin, stdout, and stderr of processes. The prototypes for these two functions are as
The system calls DUP and dup2 to copy the file descriptor. The DUP returns a new file descriptor (the smallest number that is not used by the file descriptor). Dup2 can let the user specify the value of the returned file descriptor, and, if
FILE descriptor and FILE, FILE descriptor FILE1. file descriptor (important)
In Linux, everything can be viewed as a file, which can be divided into common files, directory files, link files, and device files. File descriptor is an index created by
DUP and dup2 are two very useful calls. They are used to copy the descriptor of a file. They are often used to redirect stdin, stdout, and stderr of processes. The original form of these two functions is as follows: # include int DUP (INT oldfd);
Image Understanding dup and dup2 functions-general Linux technology-Linux programming and kernel information. The following is a detailed description. I believe that most programmers programming in Unix/Linux have the "APUE in Unix environment"
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.