Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

close(2) [osf1 man page]

close(2)							System Calls Manual							  close(2)

NAME
close - Closes the file associated with a file descriptor SYNOPSIS
#include <unistd.h> int close ( int filedes ); PARAMETERS
Specifies a valid open file descriptor. STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: close(): XSH5.0, XNS5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. DESCRIPTION
The close() function closes the file associated with the filedes parameter. All regions of a file specified by the filedes parameter that this process has previously locked with the lockf() function are unlocked. This occurs even if the process still has the file open by another file descriptor. When all file descriptors associated with a pipe or FIFO special file have been closed, any data remaining in the pipe or FIFO is dis- carded. When all file descriptors associated with an open file descriptor are closed, the open file descriptor is freed. If the link count of the file is 0 (zero) when all file descriptors associated with the file have been closed, the space occupied by the file is freed and the file is no longer accessible. When the close() function needs to block, only the calling thread is suspended rather than all threads in the calling process. The last close() for a stream causes the stream associated with fildes to be dismantled. Dismantling includes popping any modules on the stream and closing the driver. If O_NDELAY and O_NONBLOCK are clear and there are no signals posted for the stream, close() waits up to 15 seconds for each module to drain and up to 15 seconds for each driver to drain. If the O_NDELAY or the O_NONBLOCK flag is set or if there are any pending signals, close() does not wait for output to drain, and dismantles the stream immediately. If a STREAMS file is closed, and the calling process had previously registered to receive a SIGPOLL signal [see signal()] for events associated with that file [see I_SETSIG in streamio(7)], the calling process is unregistered for events associated with the file. For sockets (fildes refers to a socket), a call to close causes the socket to be destroyed. For connection-oriented sockets that have the SOCK_LINGER option set and have untransmitted data, the close function blocks for the period of time specified by the linger interval until all data is transmitted. RETURN VALUES
Upon successful completion, a value of 0 (zero) is returned. Otherwise, a value of -1 is returned and errno is set to indicate the error. ERRORS
If the close() function fails, errno may be set to one of the following values: The filedes parameter is not a valid open file descriptor. The close() function was interrupted by a signal which was caught. A read or write physical I/O error. [Tru64 UNIX] fildes is on a remote machine and the link to that machine is no longer active. [Tru64 UNIX] A close() function on an NFS file system waits for all outstanding I/O to complete. If any operation completes with an error, the error will be returned by close(). The possible errors depend on the NFS server implementation, but the most likely errors are: The write has failed because the user's disk block quota is exhausted. Attempted to write a file that exceeds the maximum file size. A read or write physical I/O error. Attempted to write on a full file system. RELATED INFORMATION
Functions: exec(2), fcntl(2), lockf(3), open(2), pipe(2), socket(2), streamio(7). Standards: standards(5). delim off close(2)

Check Out this Related Man Page

close(2)							System Calls Manual							  close(2)

Name
       close - delete a descriptor

Syntax
       close(fd)
       int fd;

Description
       The  call  deletes  a  descriptor  from	the per-process object reference table.  If the descriptor is the last reference to the underlying
       object, then the object is deactivated.	For example, on the last close of a file, the current pointer associated with the  file  is  lost.
       On  the	last  close  of a socket, discards associated naming information and queued data.  On the last close of a file holding an advisory
       lock, the lock is released.  For further information, see

       A process's descriptors are automatically closed when a process exits, but because each	process  can  have  a  limited	number	of  active
       descriptors, is necessary for programs that deal with many descriptors.

       When  a	process  forks,  all descriptors for the new child process reference the same objects as they did in the parent process before the
       fork.  For further information, see If a new process is then to be run using the process would normally inherit these descriptors.  Most of
       the  descriptors  can  be  rearranged  with the system call or deleted with before is called. However, if any descriptors are needed if the
       fails, they must be closed if the execve succeeds.  For this reason, the call, fcntl(d, F_SETFD, 1), is provided. This call arranges that a
       descriptor is closed after a successful call.  The call, fcntl(d, F_SETFD, 0), restores the default, which is to not close the descriptor.

       When  is  used  on  a  descriptor  that	refers to a remote file over NFS, and that file has been modified by using then any cached data is
       flushed before returns. If an asynchronous write error has occurred previously with this remote file, or occurred  as  part  of	the  flush
       operation described above, then returns -1 and errno will be set to the error code. The return code from should be inspected by any program
       that can over NFS.

Return Values
       Upon successful completion, a value of 0 is returned.  Otherwise, a value of -1 is returned, and the global integer variable, errno, is set
       to indicate the error.

Diagnostics
       The system call fails under the following conditions:

       [EBADF]	      D is not an active descriptor.

       [EINTR]	      The function was interrupted by a signal.

       If  an  error occurs on an asynchronous write over NFS, the error cannot always be returned from a system call.	The error code is returned
       on or The following are NFS-only error messages:

       [EACCESS]      The requested address is protected, and the current user has inadequate permission to access it.

       [ENOSPC]       There is no free space remaining on the file system containing the file.

       [EDQUOT]       The user's quota of disk blocks on the file system containing the file has been exhausted.

       [EIO]	      An I/O error occurred while reading from or writing to the file system.

       [EROFS]	      The file is on a read-only file system.

       [ESTALE]       The fd argument is invalid because the file referred to by that file handle no longer exists or has been revoked.

       [ETIMEDOUT]    A write operation failed because the server did not properly respond after a  period  of	time  that  is	dependent  on  the
		      options.

See Also
       accept(2), execve(2), fcntl(2), flock(2), fsync(2), open(2), pipe(2), socket(2), socketpair(2), write(2)

																	  close(2)
Man Page