dup.2
来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· 2 代码 · 共 80 行
2
80 行
.\" SCCSID: @(#)dup.2 8.1 9/11/90.TH dup 2.SH Namedup, dup2 \- duplicate an open file descriptor.SH Syntax.nfnewd = dup(\fIoldd\fP)int newd, \fIoldd\fP;.PPdup2(\fIoldd, newd\fP)int \fIoldd, newd\fP;.fi.SH Description.NXR "dup system call".NXR "dup2 system call".NXR "file descriptor" "duplicating".NXR "file descriptor" "process reference table"The .PN dupsystem call duplicates an existing object descriptor.The argument \fIoldd\fP is a small non-negative integer index inthe per-process descriptor table. The value must be lessthan the size of the table, which is returned by .PN getdtablesize .The new descriptor,.I newd,returned by the call 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, .PN read ,.PN write ,and.PN lseekcalls all move a single pointer into the file.If a separate pointer into the file is desired, a differentobject reference to the file must be obtained by issuing anadditional .PN opencall..PPIn the second form of the call, specify the value of.IR newdneeded. If this descriptor is alreadyin use, the descriptor is first deallocated as if a.PN closecall had been done..SH Return ValuesThe value \-1 is returned if an error occurs in either call.The external variable.I errnoindicates the cause of the error..SH DiagnosticsThe.PN dupand.PN dup2system calls fail under the following conditions:.TP 15[EBADF]The\fIoldd\fP or\fInewd\fP is not a valid active descriptor..TP 15[EMFILE]Too many descriptors are active..TP 15[EINTR]The.PN dup()or.PN dup2()function was terminated prematurely by a signal..SH See Alsoaccept(2), close(2), getdtablesize(2), lseek(2), open(2), pipe(2), read(2), socket(2),socketpair(2), write(2)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?