Devices Under the UNIX Operating System

BBj-Specific Information

In BBj, the operating system level call to open a system device occurs in BBjServices. For instance, if the device is a pseudo-terminal, the BBjServices process may not have permissions or access to the given terminal.

There is another ramification with respect to terminal devices. In many UNIX environments, the special device /dev/tty will open the terminal to which the current process is connected. Because it is the BBjServices process that opens devices, opening /dev/tty will open the terminal connected to BBjServices. This is most likely not the same terminal as the bbj process started by the user. In general, opening /dev/tty within BBjServices is not a useful concept.

PRO/5-Specific Information


The OPEN verb will also open system devices. After opening, the PRO/5 filesystem will determine whether the opened device is a block or character device. If it is a block device, the IND=int option will be allowed during READ and WRITE calls; int is passed to the device driver using the "lseek(2)" system call. There are no limits on the minimum or maximum length of records applied by PRO/5 to devices.

If you are attempting to use serial devices, you should be aware of some of the problems you may encounter. Most of these problems involve the settings of baud rate, word size, etc. on the port through the "stty" command. These settings take on the driver's default settings on the first open of the device on the system. A shell script designed to handle these problems is provided with PRO/5; this is called "openport." This script is designed to execute as a background process and as such, is invoked in the following manner:

openport /dev/tty01 1200 ixon ixoff -ixany &

This opens the "/dev/tty01" device and, via "stty", sets the port parameters to those of "openport" plus any modes you specify on the port. The script then sleeps forever (killed by the next shutdown or your log out). If you have to use this command frequently (perhaps to setup a serial printer), you may consider placing it in your system's status scripts, e.g., in "/etc/rc."

The "openport" script willnotfunction properly when run under the "c-shell."

Pipes in PRO/5 and BBj


In PRO/5 15.01 and higher, and BBj 15.10 and higher, the OPEN verb by default is restricted from opening pipes (commands starting with "<", ">", or "|") in console mode. This is to protect against accidentally overwriting a data file as a side effect of inadvertently specifying a pipe expression. To open a pipe at the console, set SETOPTS byte 9 bit $10$ or include MODE="PIPE" in the OPEN.

PRO/5 and BBj will allow you to open inter-process communication channels called "pipes." A pipe is created by starting the name with the character: "<" for a read pipe, ">" for a write pipe, and "|" for a bi-directional pipe (both read and write). An attempt to read or write to a broken pipe (one which has lost its other end) will result in an !ERROR=2 (!ERROR=0 if the pipe is ALIASed as a printer).

When opening a pipe, PRO/5 and BBj will perform some argument replacement in the command line passed to the shell. Anything in the command line starting with a "$" character and ending in a non-alphanumeric character is searched for in the modes specified in the OPEN "MODE=" string and then the modes in the ALIAS entry (if the OPEN name was found in the ALIAS list). Typical replacements are "COPIES" and "FORM", both of which are normally used in spooling. See Modes Common to All ALIAS Devices.

If you need to close the "write" end of a bi-directional pipe, the following will close the write handle, leaving the read handle alone:

WRITE {RECORD}((channelno),IND=0)

Any further attempt to write to the channel will generate an error.

A pipe is a mechanism that allows First-In, First-Out (FIFO) communications flow. Pipes can be unnamed as is the case when they are created with the characters "<", ">", and "|", or pipes can be named. Named pipes have the advantage that many processes can read and write to them because they are registered with the filesystem (therefore, visible). Additionally, because named pipes are FIFO structured, they guarantee first come, first serve delivery of messages (data). Please consult your UNIX documentation for a more thorough description of pipes. In particular, see Intro(2) and Mknod(1).

"Ghost" Tasks

On multi-tasking systems such as the UNIX operating system, PRO/5 supports the definition of an ALIAS which, when opened, will run as a background process. For example the following will cause an invocation PRO/5 with BBTERM set to "G0" when an OPEN of the G0 device is done within PRO/5:

ALIAS G0 "|BBTERM=G0 pro5"

This starts PRO/5 at the end of a bi-directional pipe. As an alternative, the SCALL() function may be used with a trailing ampersand (&), or from PRO/5 console mode, the system call function (!) can be used to start background tasks in UNIX. The console mode system call function is covered under Additional PRO/5 Command Information For the UNIX Operating System. Note that you may also use the BACKGROUND verb.