Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

creat(2)

dup(2)

exec(2)

fcntl(2)

intro(2)

open(2)

pipe(2)

signal(2)

signal(5)

streamio(7)

fattach(3C)

fdetach(3C)



close(2)                  SYSTEM CALLS                   close(2)



NAME
     close - close a file descriptor

SYNOPSIS
     #include <unistd.h>
     int close(int fildes);

DESCRIPTION
     fildes is a file descriptor obtained  from  a  creat,  open,
     dup,  fcntl,  or  pipe  system  call.  close closes the file
     descriptor indicated  by  fildes.   All  outstanding  record
     locks owned by the process (on the file indicated by fildes)
     are removed.

     When all file descriptors  associated  with  the  open  file
     description  have  been closed, the open file description is
     freed.

     If the link count  of  the  file  is  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.

     If a STREAMS-based [see intro(2)] fildes is closed, and  the
     calling  process had previously registered to receive a SIG-
     POLL signal [see signal(2)] for events associated with  that
     stream  [see  I_SETSIG  in streamio(7)], the calling process
     will be unregistered for events associated with the  stream.
     The  last  close  for  a stream causes the stream associated
     with fildes to be dismantled.  If  O_NDELAY  and  O_NONBLOCK
     are  clear  and  there  have  been no signals posted for the
     stream, and if there are data on the module's  write  queue,
     close  waits  up  to 15 seconds (for each module and driver)
     for any output to drain before dismantling the stream.   The
     time  delay  can be changed via an I_SETCLTIME ioctl request
     [see streamio(7)].  If O_NDELAY or O_NONBLOCK is set, or  if
     there  are any pending signals, close does not wait for out-
     put to drain, and dismantles the stream immediately.

     If fildes is associated with one end of  a  pipe,  the  last
     close causes a hangup to occur on the other end of the pipe.
     In addition, if the other end of the  pipe  has  been  named
     [see fattach(3C)], the last close forces the named end to be
     detached [see fdetach(3C)].  If the named end  has  no  open
     processes  associated  with  it  and  becomes  detached, the
     stream associated with that end is also dismantled.

     The named file is closed unless one or more of the following
     are true:

     EBADF          fildes is not a valid open file descriptor.




                                                                1





close(2)                  SYSTEM CALLS                   close(2)



     EINTR          A signal was caught during the  close  system
                    call.

     ENOLINK        fildes is on a remote machine and the link to
                    that machine is no longer active.

SEE ALSO
     creat(2),  dup(2),  exec(2),  fcntl(2),  intro(2),  open(2),
     pipe(2), signal(2), signal(5), streamio(7).
     fattach(3C), fdetach(3C) in the Programmer's Guide: Network-
     ing Interfaces.

DIAGNOSTICS
     Upon successful completion, a value of 0 is returned.   Oth-
     erwise,  a value of -1 is returned and errno is set to indi-
     cate the error.







































                                                                2



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026