> Linux Reviews > man >

close

close


  1. close.2.man
  2. close.9.man


1. close.2.man

Manpage of CLOSE

CLOSE

Section: Systemaufrufe (2)
Updated: 20. April 1999
Index Return to Main Contents
 

BEZEICHNUNG

close - Datei-Deskriptor schließen  

ÜBERSICHT

#include <unistd.h>

intclose(intfd);
 

BESCHREIBUNG

close schließt einen Datei-Deskriptor, so dass dieser nicht mehr zu einer Datei gehört und wieder verwendet werden kann. Alle Sperren, mit denen die Datei belegt ist und die zu diesem Prozess gehören, werden aufgehoben (unabhängig von dem Datei-Deskriptor, mit dem die Sperre eingerichtet wurde).

Wenn fd die letzte Kopie eines bestimmten Datei-Deskriptors ist, werden die zugehörigen Ressourcen freigegeben. War der Datei-Deskriptor der letzte Verweis auf eine Datei, die mit unlink entfernt wurde, dann wird die Datei gelöscht.  

RÜCKGABEWERT

close gibt im Erfolgsfall 0 zurück und bei Auftreten eines Fehlers -1.  

FEHLER

EBADF
fd ist kein gültiger geöffneter Datei-Deskriptor.
 

KONFORM ZU

SVr4, SVID, POSIX, X/OPEN, BSD 4.3. SVr4 dokumentiert eine zusätzliche ENOLINK Fehlerbedingung.  

ANMERKUNGEN

Es ist ein verbreiteter aber ernster Programmierfehler, den Rückgabewert von close nicht zu prüfen. Im Verbund mit Dateisystemen, die Techniken wie ``write-behind'' zur Verbesserung der Performance einsetzen, kann dies einen erfolgreichen write(2) -Vorgang vortäuschen, obwohl die Daten noch nicht geschrieben wurden. Der Fehlerstatus könnte zwar bei einem späteren Schreibvorgang festgestellt werden, muss aber bei Schließen der Datei ausgewertet werden. Wird der Rückgabewert beim Schließen einer Datei nicht geprüft, kann dies zu unbemerktem Datenverlust führen. Dies ist insbesondere bei NFS mit Disk-Quotas zu beobachten.  

SIEHE AUCH

open(2), fcntl(2), shutdown(2), unlink(2), fclose(3).


 

Index

BEZEICHNUNG
ÜBERSICHT
BESCHREIBUNG
RÜCKGABEWERT
FEHLER
KONFORM ZU
ANMERKUNGEN
SIEHE AUCH

This document was created by man2html using the manual pages.
Time: 23:24:18 GMT, July 09, 2008

2. close.9.man

Manpage of close

close

Section: Tcl Built-In Commands (n)
Updated: 7.5
Index Return to Main Contents



 

NAME

close - Close an open channel.  

SYNOPSIS

close channelId



 

DESCRIPTION

Closes the channel given by channelId.

ChannelId must be an identifier for an open channel such as a Tcl standard channel (stdin, stdout, or stderr), the return value from an invocation of open or socket, or the result of a channel creation command provided by a Tcl extension.

All buffered output is flushed to the channel's output device, any buffered input is discarded, the underlying file or device is closed, and channelId becomes unavailable for use.

If the channel is blocking, the command does not return until all output is flushed. If the channel is nonblocking and there is unflushed output, the channel remains open and the command returns immediately; output will be flushed in the background and the channel will be closed when all the flushing is complete.

If channelId is a blocking channel for a command pipeline then close waits for the child processes to complete.

If the channel is shared between interpreters, then close makes channelId unavailable in the invoking interpreter but has no other effect until all of the sharing interpreters have closed the channel. When the last interpreter in which the channel is registered invokes close, the cleanup actions described above occur. See the interp command for a description of channel sharing.

Channels are automatically closed when an interpreter is destroyed and when the process exits. Channels are switched to blocking mode, to ensure that all output is correctly flushed before the process exits.

The command returns an empty string, and may generate an error if an error occurs while flushing output. If a command in a command pipeline created with open returns an error, close generates an error (similar to the exec command.)  

EXAMPLE

This illustrates how you can use Tcl to ensure that files get closed even when errors happen by combining catch, close and return:

proc withOpenFile {filename channelVar script} {
    upvar 1 $channelVar chan
    set chan [open $filename]
    catch {
        uplevel 1 $script
    } result options
    close $chan
    return -options $options $result
}

 

SEE ALSO

file(n), open(n), socket(n), eof(n), Tcl_StandardChannels(3)

 

KEYWORDS

blocking, channel, close, nonblocking


 

Index

NAME
SYNOPSIS
DESCRIPTION
EXAMPLE
SEE ALSO
KEYWORDS

This document was created by man2html using the manual pages.
Time: 23:24:18 GMT, July 09, 2008

NORSK BOKMÅL - NORSK BOKMÅL - NORSK BOKMÅL - NORSK BOKMÅL - da - nl - NORSK BOKMÅL - pl