Using Null Devices

Null devices comprise of a collection of system purpose devices that include /dev/null, /dev/zero, /dev/random, and /dev/urandom.

A null device discards all output. GT.M maintains a virtual cursor position for null devices as it does for terminals on output. Use null devices for program testing and debugging, or for jobs that permit I/O to be discarded under certain circumstances. For example, JOB processes must have input and output devices associated with them, even though they do not use them. Null devices are low overhead never-fail alternatives for certain classes of I/O.

Null Deviceparameter Summary

The following table provides a brief summary of deviceparameters for null devices. For more detailed information, refer to “Open”, “Use”, and “Close”.

Null Deviceparameters




O: Applies to the OPEN command

U: Applies to the USE command

C: Applies to the CLOSE command



Controls device-specified error handling. For the null device this is only EOF handling and therefore exceptions can never be invoked except by a READ.



Controls some $X,$Y maintenance.



Controls the length of the virtual page.



Controls maximum size of a record.



Controls handling of records longer than the maximum width.



Sets $X to intexpr.



Sets $Y to intexpr.

Null Device Examples

This section contains examples of null device usage.


GTM>do ^runrep
 zprint ^runrep
 set dev="/dev/null"
 set hdr="********* REPORT HEADER ************"
 open dev use dev
 set x="" write hdr,!,$zdate($horolog),?30,$job,!
 for  set x=$order(^tmp($job,x)) quit:x=""  do REPORT
 ;large amount of code

This program produces a report derived from the information in the global variable ^tmp. The unspecified routine REPORT may potentially contain a large amount of code. To see that the basic program functions without error, the programmer may discard the output involved in favor of watching the function. To run the program normally, the programmer simply has to change the variable dev to name another device and the routine REPORT writes to the dev device.


job ^X:(in="/dev/null":out="/dev/null":err="error.log")
JOB ^X:(IN="/dev/null":OUT="/dev/null":ERR="error.log") 

This example issues a GT.M JOB command to execute the routine ^X in another process. This routine processes a large number of global variables and produces no output. In the example, the JOBbed process takes its input from a null device, and sends its output to a null device. If the JOBbed process encounters an error, it directs the error message to error.log.