74 lines
2.9 KiB
HTML
74 lines
2.9 KiB
HTML
<HTML>
|
|
<HEAD>
|
|
<TITLE>close(2)</TITLE>
|
|
</HEAD>
|
|
<BODY>
|
|
<H1>close(2)</H1>
|
|
<HR>
|
|
<PRE>
|
|
|
|
</PRE>
|
|
<H2>NAME</H2><PRE>
|
|
close - delete a descriptor
|
|
|
|
|
|
</PRE>
|
|
<H2>SYNOPSIS</H2><PRE>
|
|
<STRONG>#include</STRONG> <STRONG><unistd.h></STRONG>
|
|
|
|
<STRONG>int</STRONG> <STRONG>close(int</STRONG> <EM>d</EM><STRONG>)</STRONG>
|
|
|
|
|
|
</PRE>
|
|
<H2>DESCRIPTION</H2><PRE>
|
|
The <STRONG>close</STRONG> call deletes a descriptor from the per-process object reference
|
|
table. If this is the last reference to the underlying object, then it
|
|
will be deactivated. For example, on the last close of a file the
|
|
current <EM>seek</EM> pointer associated with the file is lost; on the last close
|
|
of a TCP/IP descriptor associated naming information and queued data are
|
|
discarded; on the last close of a file holding an advisory lock the lock
|
|
is released (see further <STRONG><A HREF="../man2/fcntl.2.html">fcntl(2)</A></STRONG>).
|
|
|
|
A close of all of a process's descriptors is automatic on <EM>exit</EM>, but since
|
|
there is a limit on the number of active descriptors per process, <STRONG>close</STRONG>
|
|
is necessary for programs that deal with many descriptors.
|
|
|
|
When a process forks (see <STRONG><A HREF="../man2/fork.2.html">fork(2)</A></STRONG>), all descriptors for the new child
|
|
process reference the same objects as they did in the parent before the
|
|
fork. If a new process is then to be run using <STRONG><A HREF="../man2/execve.2.html">execve(2)</A></STRONG>, the process
|
|
would normally inherit these descriptors. Most of the descriptors can be
|
|
rearranged with <STRONG><A HREF="../man2/dup2.2.html">dup2(2)</A></STRONG> or deleted with <STRONG>close</STRONG> before the <STRONG>execve</STRONG> is
|
|
attempted, but if some of these descriptors will still be needed if the
|
|
<STRONG>execve</STRONG> fails, it is necessary to arrange for them to be closed if the
|
|
<STRONG>execve</STRONG> succeeds. For this reason, the call ``fcntl(d, F_SETFD, <EM>flags</EM>)''
|
|
is provided, that can be used to mark a descriptor "close on exec" by
|
|
setting the <STRONG>FD_CLOEXEC</STRONG> flag:
|
|
|
|
fcntl(d, F_SETFD, fcntl(d, F_GETFD) | FD_CLOEXEC);
|
|
|
|
|
|
</PRE>
|
|
<H2>RETURN VALUE</H2><PRE>
|
|
Upon successful completion, a value of 0 is returned. Otherwise, a value
|
|
of -1 is returned and the global integer variable <STRONG>errno</STRONG> is set to
|
|
indicate the error.
|
|
|
|
|
|
</PRE>
|
|
<H2>ERRORS</H2><PRE>
|
|
<STRONG>Close</STRONG> will fail if:
|
|
|
|
[EBADF] <EM>D</EM> is not an active descriptor.
|
|
|
|
|
|
</PRE>
|
|
<H2>SEE ALSO</H2><PRE>
|
|
<STRONG><A HREF="../man2/open.2.html">open(2)</A></STRONG>, <STRONG><A HREF="../man2/pipe.2.html">pipe(2)</A></STRONG>, <STRONG><A HREF="../man2/execve.2.html">execve(2)</A></STRONG>, <STRONG><A HREF="../man2/fcntl.2.html">fcntl(2)</A></STRONG>.
|
|
|
|
|
|
|
|
|
|
</PRE>
|
|
</BODY>
|
|
</HTML>
|