FIFO Characteristics

FIFOs have most of the same characteristics as other sequential files, except that READs and WRITEs can occur in any order.

The following characteristics of FIFO behavior may be helpful in using them effectively.

With READ:

The process hangs until data is put into the FIFO by another process, or the READ times out, when a timeout is specified.

The following table shows the result and the values of I/O status variables for different types of READ operations on a FIFO device.

Operation

Result

$DEVICE

$ZA

$TEST

X

$ZEOF

READ X:n

Normal Termination

0

0

1

Data Read

0

READ X:n

Timeout with no data read

0

0

0

empty string

0

READ X:n

Timeout with partial data read

0

0

0

Partial data

0

READ X:n

End of File

1,Device detected EOF

9

1

empty string

1

READ X:0

Normal Termination

0

0

1

Data Read

0

READ X:0

No data available

0

0

0

empty string

0

READ X:0

Timeout with partial data read

0

0

0

Partial data

0

READ X:0

End of File

1,Device detected EOF

9

1

empty string

1

READ X

Error

1,<error signature>

9

n/c

empty string

0

With WRITE:

With CLOSE:

The default access permissions on a FIFO are the same as the mask settings of the process that created the FIFO. Use the SYSTEM, GROUP, WORLD, and UIC deviceparameters to specify FIFO access permissions. File permissions have no affect on a process that already has the FIFO open.

Considerations in Implementing FIFOs

As you establish FIFOs for interprocess communication, consider whether, and how, the following issues will be addressed:

  • Do READs occur immediately, or can the process wait?

  • Are timed READs useful to avoid system hangs and provide a way to remove the process?

  • Does the WRITE process need to know whether the READ data was received?

  • Will there be multiple processes READing and WRITEing into a single FIFO?

Error Handling for FIFOs

Deleting devices (or files) created by an OPEN which has an error has deeper implications when that device, especially a FIFO, serves as a means of communications between a two processes. If one process OPENs a FIFO device for WRITE, there is an interval during which another process can OPEN the same device for READ. During that interval the writer process can encounter an error (for example, an invalid parameter) causing GT.M to delete the device, but the reader process can complete its OPEN successfully. This sequence results in a process with an orphaned device open for READ. Any other process that OPENs the same device for WRITE creates a new instance of it, so the reader can never find data to READ from the orphaned device. Since GT.M has insufficient context to enforce process synchronization between reader and writer, the application must use appropriate communication protocols and error handling techniques to provide synchronization between processes using files and FIFOs for communication.

GT.M Recognition of FIFOs

Like a sequential file, the path of a FIFO is specified as an argument expression to the OPEN, USE, and CLOSE commands. A device OPENed with a FIFO deviceparameter becomes a FIFO unless another device of that name is already OPEN. In that case, OPENing a device that has previously been OPENed by another process as a FIFO causes the process (the process here is the process trying to open the FIFO) to attach to the existing FIFO.

[Note] Note

If an existing named pipe (aka fifo special file) is OPENed even without specifying the FIFO deviceparameter, it is treated as if FIFO had been specified.

FIFO Device Examples

The following two examples represent a master/slave arrangement where the slave waits in a read state on the FIFO until the master sends it some data that it then processes.

Example:

set x="named.pipe"
open x:fifo
do getres
use x write res,!

This routine opens the FIFO, performs its own processing which includes starting the slave process (not shown in this code fragment).

Example:

set x="named.pipe"
open x:fifo
use x read res
do process(res)

This routine waits for information from the master process, then begins processing.

FIFO Deviceparameter Summary

The following table summarizes the deviceparameters that can be used with FIFOs.

File Format Deviceparameters

DEVICEPARAMETER

CMD

DESCRIPTION

[NO]FIXED

O

Controls whether records have fixed length.

[Z]LENGTH=intexpr

U

Controls the virtual page length.

RECORDSIZE=intexpr

O

Specifies the maximum record size.

VARIABLE

O

Controls whether records have variable length.

[Z]WIDTH=intexpr

U

Sets the device's logical record size and enables WRAP.

[Z][NO]WRAP

O/U

Controls the handling of records longer than the device width.

File Access Deviceparameters

DEVICEPARAMETER

CMD

COMMENT

DELETE

C

Specifies that the FIFO should be deleted when the last user closes it. If specified on an OPEN, DELETE is activated only at the time of the close. No new attachements are allowed to a deleted FIFO and any new attempt to use a FIFO with the name of the deleted device creates a new device.

GROUP=expr

O/C

Specifies file permissions for other users in owner's group.

[NO]READONLY

O

OPENs a device for reading only (READONLY) or reading and writing (NOREADONLY).

OWNER=expr

O/C

Specifies file permissions for owner of file.

RENAME=expr

C

Specifies that CLOSE rename a disk file with the name specified by the expression.

REPLACE=expr

C

Specifies that CLOSE replace(overwrite an existing file if necessary) the name of a disk file with the name specified by the expression.

SYSTEM=expr

O/C

Specifies file permissions for owner of file (same as OWNER).

UIC=expr

O/C

Specifies the file's owner ID.

WORLD=expr

O/C

Specifies file permissions for users not in the owner's group.