Duplicate this file descriptor and return the newly created copy.
func duplicate(as target: FileDescriptor? = nil, retryOnInterrupt: Bool = true) throws -> FileDescriptor
The desired target file descriptor, or
nil, in which case the copy is assigned to the file descriptor with the lowest raw value that is not currently in use by the process.
The new file descriptor.
target descriptor is already in use, then it is first deallocated as if a close(2) call had been done first.
File descriptors are merely references to some underlying system resource. The system does not distinguish between the original and the new file descriptor in any way. For example, read, write and seek operations on one of them also affect the logical file position in the other, and append mode, non-blocking I/O and asynchronous I/O options are shared between the references. If a separate pointer into the file is desired, a different object reference to the file must be obtained by issuing an additional call to
However, each file descriptor maintains its own close-on-exec flag.
The corresponding C functions are