close()


Close a file or process channel.

Syntax

close(channel,[flags])

 

Parameters

Parameter

Definition

channel

process or file I/O channel name (shared channels) or number (local channels) that is to be closed

flags

optional bit flags used to control close execution The following bits are used:

  • Bit 1 = 1 indicates that any system process associated with the channel (that is, the PSL fopen() or popen() function) should be killed while closing the channel
  • Bit 2 = 1 indicates that the channel should be closed even if another PSL process is blocked waiting for a read(),readln(), or write() function. Bit 2 applies only to global channels and is ignored by local channels.

Default
Bits 1 and 2 are both zero.

 

Description

The close() function closes a channel to a process or command previously created by a fopen() or popen() call. 

When flags are not specified, the default is zero. 

When bit 1 = 0, the close() function does not kill any processes spawned as a result of the fopen() or popen(), and these processes are allowed to continue. This feature of close() allows you to open a channel to a PSL process, send additional data, and close the channel while allowing the process to complete. 

When bit 2 = 1, the close() function will close the channel even if another PSL process is blocked pending an I/O request on that channel. When blocking occurs, close() causes the blocked function to wake and receive an error return anderrno from the process to which the channel was opened. 

The close() function returns the NULL string if the closure was successful and -1 with the PSL variable errno set if the closure was unsuccessful. The close() function fails when bit 2 = 0 and channel is a global channel with at least one blocked PSL process.

Example

This example closes the channel that is represented by chan:

close(chan);
close(chan,1); # bit 1 set
close(chan,2); # bit 2 set (2 is binary 10)
close(chan,3); # both bits set (3 is binary 11)