The Pipe File Manager (PIPEMAN)
The Pipe File Manager (PIPEMAN)
The Pipe file manager handles control or processes that use paths to pipes. Pipes allow concurrently executing processes to send each other data by using the output of one process (the writer) as input to a second process (the reader). The reader gets input from the standard input. The exclamation point (!) operator specifies that the input or output is from or to a pipe. The Pipe file manager allocates a 256-byte block and a path descriptor for data transfer. The Pipe file manager also determines which process has control of the pipe. The Pipe file manager has the standard file manager branch table at its entry point:
ENTRY LBRA Create LBRA Open LBRA MakDir LBRA ChgDir LBRA Delete LBRA Seek LBRA PRead LBRA PWrite LBRA PRdLn LBRA PWrLn LBRA GetStat LBRA SetStat LBRA Close
You cannot use MakDir, ChgDir, Delete, and Seek with pipes. If you try to do so, the system returns E$UNKSVC (unknown service request). GetStat and SetStat are also no-action service routines. They return without error.
Create and Open perform the same functions. They set up the 256-byte data exchange buffer and save several addresses in the path descriptor.
The Close request checks to see if any process is reading or writing through the pipe. If not, NitrOS-9 returns the buffer.
PRead, PWrite, PRdLn, and PWrLn read data from the buffer and write data to it.
The ! operator tells the Shell that processes wish to communicate through a pipe. For example:
poc1 ! proc2
In this example, shell forks Proc1 with the standard output path to a pipe and forks Proc2 with the standard input path from a pipe.
Shell can also handle a series of processes using pipe. For example:
proc1 ! proc2 ! proc3 ! proc4
The following outline shows how to set up pipes between processes:
- Open /pipe save path in variable x
- Dup path #1 save stdout in variable y
- Close #1 make path available
- Dup x put pipe in stdout
- (Dup uses lowest available)
- Fork proc1 fork process 1
- Close #1 make path available
- Dup y restore stdout
- Close y make path available
- Dup path #0 save stdin in Y
- Close #0 make path available
- Dup x put pipe in stdin
- Fork proc2 fork process 2
- Close #0 make path available
- Dup y restore stdin
- Close x no longer needed
- Close y no longer needed
Example: The following example shows how an application can initiate another process with the stdin and stdout routed through a pipe:
- Open /pipe1 save path in variable a
- Open /pipe2 save path in variable b
- Dup 0 save stdin in variable x
- Dup 1 save stdout in variable y
- Close #0 make stdin path available
- Close #1 make stdout path available
- Dup a make pipe1 stdin
- Dup b make pipe2 stdout
- Fork new process
- Close #0 make stdin path available
- Close #1 make stdout path available
- Dup x restore stdin
- Dup y restore stdout
- Return a&b return pipe path numbers to caller