⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dup.2

📁 Unix操作系统minix 2.0源码
💻 2
字号:
.\" Copyright (c) 1980 Regents of the University of California..\" All rights reserved.  The Berkeley software License Agreement.\" specifies the terms and conditions for redistribution..\".\"	@(#)dup.2	6.3 (Berkeley) 5/13/86.\".TH DUP 2 "May 13, 1986".UC 4.SH NAMEdup, dup2 \- duplicate a descriptor.SH SYNOPSIS.nf.ft B#include <unistd.h>int dup(int \fIoldd\fP)int dup2(int \fIoldd\fP, int \fInewd\fP).SH DESCRIPTION.B Dupduplicates an existing descriptor.The argument \fIoldd\fP is a small non-negative integer index inthe per-process descriptor table.  The value must be lessthan OPEN_MAX, the size of the table.The new descriptor returned by the call, let's name it.I newd,is the lowest numbered descriptor that isnot currently in use by the process..PPThe object referenced by the descriptor does not distinguishbetween references using \fIoldd\fP and \fInewd\fP in any way.Thus if \fInewd\fP and \fIoldd\fP are duplicate references to an openfile,.BR read (2),.BR write (2)and.BR lseek (2)calls all move a single pointer into the file,and append mode, non-blocking I/O and asynchronous I/O optionsare shared between the references.If a separate pointer into the file is desired, a differentobject reference to the file must be obtained by issuing anadditional.BR open (2)call.The close-on-exec flag on the new file descriptor is unset..PPIn the second form of the call, the value of.IR newddesired is specified.  If this descriptor is alreadyin use, the descriptor is first deallocated as if a.BR close (2)call had been done first..I Newdis not closed if it equals.IR oldd ..SH "RETURN VALUEThe value \-1 is returned if an error occurs in either call.The external variable.B errnoindicates the cause of the error..SH "ERRORS.B Dupand.B dup2fail if:.TP 15[EBADF]\fIOldd\fP or\fInewd\fP is not a valid active descriptor.TP 15[EMFILE]Too many descriptors are active..SH NOTES.B Dupand.B dup2are now implemented using the.B F_DUPFDfunction of.BR fcntl (2),although the old system call interfaces still exist to support old programs..SH "SEE ALSO".BR open (2),.BR close (2),.BR fcntl (2),.BR pipe (2).

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -