source: trunk/minix/man/man2/close.2@ 20

Last change on this file since 20 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 2.2 KB
Line 
1.\" Copyright (c) 1980 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
5.\" @(#)close.2 6.3 (Berkeley) 5/22/86
6.\"
7.TH CLOSE 2 "May 22, 1986"
8.UC 4
9.SH NAME
10close \- delete a descriptor
11.SH SYNOPSIS
12.nf
13.ft B
14#include <unistd.h>
15
16int close(int \fId\fP)
17.ft R
18.fi
19.SH DESCRIPTION
20The
21.B close
22call deletes a descriptor from the per-process object
23reference table.
24If this is the last reference to the underlying object, then
25it will be deactivated.
26For example, on the last close of a file
27the current \fIseek\fP pointer associated with the file is lost;
28on the last close of a TCP/IP descriptor
29associated naming information and queued data are discarded;
30on the last close of a file holding an advisory lock
31the lock is released (see further
32.BR fcntl (2)).
33.PP
34A close of all of a process's descriptors is automatic on
35.IR exit ,
36but since
37there is a limit on the number of active descriptors per process,
38.B close
39is necessary for programs that deal with many descriptors.
40.PP
41When a process forks (see
42.BR fork (2)),
43all descriptors for the new child process reference the same
44objects as they did in the parent before the fork.
45If a new process is then to be run using
46.BR execve (2),
47the process would normally inherit these descriptors. Most
48of the descriptors can be rearranged with
49.BR dup2 (2)
50or deleted with
51.B close
52before the
53.B execve
54is attempted, but if some of these descriptors will still
55be needed if the
56.B execve
57fails, it is necessary to arrange for them to be closed if the
58.B execve
59succeeds.
60For this reason, the call ``fcntl(d, F_SETFD, \fIflags\fR)'' is provided,
61that can be used to mark a descriptor "close on exec" by setting
62the
63.B FD_CLOEXEC
64flag:
65.PP
66.RS
67fcntl(d, F_SETFD, fcntl(d, F_GETFD) | FD_CLOEXEC);
68.RE
69.SH "RETURN VALUE
70Upon successful completion, a value of 0 is returned.
71Otherwise, a value of \-1 is returned and the global integer variable
72.B errno
73is set to indicate the error.
74.SH ERRORS
75.B Close
76will fail if:
77.TP 15
78[EBADF]
79\fID\fP is not an active descriptor.
80.SH "SEE ALSO"
81.BR open (2),
82.BR pipe (2),
83.BR execve (2),
84.BR fcntl (2).
Note: See TracBrowser for help on using the repository browser.