Using Subprocesses: The SPAWN Command

Since OpenVMS can support an arbitrary number of concurrent processes, you can create a temporary subprocess to perform time-consuming commands without tying up your terminal.

The SPAWN command creates a subprocess and optionally causes it to execute the command you specify.

The SPAWN command with no arguments creates a subprocess and attaches your terminal to it. Your original process hibernates while you use the subprocess:

    $ SPAWN    %DCL-S-SPAWNED, process MIKE_1 spawned    %DCL-S-ATTACHED, terminal now attached to process MIKE_1    $ 

Any commands you issue will be carried out by the subprocess. To end the subprocess and return to your original process, log out:

    $ LOGOUT      Process MIKE_1 logged out at 7-OCT-2002 12:22:31.29    %DCL-S-RETURNED, control returned to process MIKE:    $ 

One might wonder how that feature alone is a benefit. The answer is that the SPAWN command does not disturb the process program (P0) region. Put another way, you can interrupt a long program by pressing CTRL/Y, then SPAWN a subprocess, enter some commands, log out, and continue the original program with the DCL CONTINUE command.

While the subprocess exists, you can switch your terminal between the parent process and the subprocess by using the ATTACH command:

    $ SPAWN    %DCL-S-SPAWNED, process MIKE_1 spawned    %DCL-S-ATTACHED, terminal now attached to process MIKE_1    $ ATTACH MIKE    %DCL-S-RETURNED, control returned to process MIKE    $ ATTACH MIKE_1    %DCL-S-RETURNED, control returned to process MIKE_1    $ LOGOUT      Process MIKE_1 logged out at  7-OCT-2002 12:38:59.78    %DCL-S-RETURNED, control returned to process MIKE: 

The SPAWN command can also be used to pass a command to the subprocess. Let's say that you wanted to compile a very large C program, which might take a long time. You could create a subprocess to compile the program, as follows:

    $ SPAWN/NOWAIT CC MYPROGRAM.C    %DCL-S-SPAWNED, process MIKE_1 spawned    $ 

When the compilation finishes, the subprocess will terminate.

The /NOWAIT qualifier specifies that your terminal should remain attached to your original process and not wait for the subprocess to finish. The subprocess compiles the program, while you are free to enter other commands. In this example, any output produced by the subprocess, such as compiler error messages, will be delivered to your terminal. To direct subprocess output to a file, add the /OUTPUT=file qualifier:

     $ SPAWN/NOWAIT/OUTPUT=COMPILER.LST CC MYPROGRAM.C 

You can discard subprocess output by directing it to the NULL device. The NULL device is an OpenVMS construct that acts like an I/O device, but discards any data sent to it. It is represented by the device name "NL:".

     $ SPAWN/NOWAIT/OUTPUT=NL: PURGE [...]*.* 

Use caution when discarding output in this way. Any useful messages will be permanently lost.



Getting Started with OpenVMS(c) A Guide for New Users
Getting Started with OpenVMS: A Guide for New Users (HP Technologies)
ISBN: 1555582796
EAN: 2147483647
Year: 2005
Pages: 215

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net