📄 close.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..\".\" @(#)close.2 6.3 (Berkeley) 5/22/86.\".TH CLOSE 2 "May 22, 1986".UC 4.SH NAMEclose \- delete a descriptor.SH SYNOPSIS.nf.ft B#include <unistd.h>int close(int \fId\fP).ft R.fi.SH DESCRIPTIONThe.B closecall deletes a descriptor from the per-process objectreference table.If this is the last reference to the underlying object, thenit will be deactivated.For example, on the last close of a filethe current \fIseek\fP pointer associated with the file is lost;on the last close of a TCP/IP descriptorassociated naming information and queued data are discarded;on the last close of a file holding an advisory lockthe lock is released (see further.BR fcntl (2))..PPA close of all of a process's descriptors is automatic on.IR exit ,but sincethere is a limit on the number of active descriptors per process,.B closeis necessary for programs that deal with many descriptors..PPWhen a process forks (see.BR fork (2)),all descriptors for the new child process reference the sameobjects as they did in the parent before the fork.If a new process is then to be run using.BR execve (2),the process would normally inherit these descriptors. Mostof the descriptors can be rearranged with.BR dup2 (2)or deleted with.B closebefore the.B execveis attempted, but if some of these descriptors will stillbe needed if the.B execvefails, it is necessary to arrange for them to be closed if the.B execvesucceeds.For this reason, the call ``fcntl(d, F_SETFD, \fIflags\fR)'' is provided,that can be used to mark a descriptor "close on exec" by settingthe.B FD_CLOEXECflag:.PP.RSfcntl(d, F_SETFD, fcntl(d, F_GETFD) | FD_CLOEXEC);.RE.SH "RETURN VALUEUpon successful completion, a value of 0 is returned.Otherwise, a value of \-1 is returned and the global integer variable.B errnois set to indicate the error..SH ERRORS.B Closewill fail if:.TP 15[EBADF]\fID\fP is not an active descriptor..SH "SEE ALSO".BR open (2),.BR pipe (2),.BR execve (2),.BR fcntl (2).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -