HP OpenVMS Systems Documentation
OpenVMS User's Manual
15.6.3 Formatting Output Strings
You can use the WRITE command to write a string to a record. To line up columns in a record, you can use the F$FAO function to define record fields and place the process name and user name in these fields. When you use the F$FAO function, use a control string to define the fields in the record; then specify the values to be placed in these fields.
Another way to format fields in a record is to use a character string overlay. Note, however, that the F$FAO function is more powerful than a character string overlay. You can perform a wider range of output operations with the F$FAO function.
The command procedure shown in the following example uses the WRITE command to display the process name and PID number for processes on the system:
Note that the output from the WRITE command inserts five spaces between the process name and the user name but the columns do not line up:
The command procedure in this example uses the F$FAO function to define a 16-character field and a 12-character field. The F$FAO function places the process name in the first field, skips a space, and then places the PID number in the second field:
Now when you execute the procedure, the columns will align:
The following example uses an overlay to place the process name in the first 16 characters (starting at offset 0) of the symbol RECORD. Then the PID number is placed in the next 12 characters (starting at offset 17).
This procedure produces the same type of formatted columns you created with the F$FAO function:
15.7 Manipulating Data Types
You can use the following lexical functions to convert data from strings to integers and from integers to strings:
15.7.1 Converting Data Types
Use the F$INTEGER and F$STRING functions to convert between integers and strings. For example, the following command procedure converts data types. If you enter a string, the command procedure shows the integer equivalent. If you enter an integer, the command procedure shows the string equivalent. Note how the F$TYPE function is used to form a label name in the GOTO statement; F$TYPE returns "STRING" or "INTEGER" depending on the data type of the symbol.
15.7.2 Evaluating Expressions
Some commands, such as INQUIRE and READ, accept only string data. If you use these commands to obtain data that you want to evaluate as an integer expression, use the F$INTEGER function to convert and evaluate this data.
Note that you must place apostrophes (' ') around the symbol EXP when you use it as an argument for the F$INTEGER function. This causes DCL to substitute the value for EXP during the first phase of symbol substitution.
In the following example, the F$INTEGER function is used to evaluate an integer expression:
The output from this command procedure would be as follows:
The value "9 + 7" is substituted. When the F$INTEGER function
processes the argument "9 + 7," it evaluates the expression
and returns the correct result.
Use the F$TYPE function to determine whether a symbol exists. The F$TYPE function returns a null string if a symbol is undefined. For example:
This procedure tests whether the symbol TEMP has been previously defined. If it has, then the current value of TEMP is retained. If TEMP is not defined, then the IF statement assigns the value "YES" to TEMP.
11-DEC-2002 13:30:37.12 (1) User: CLEAVER (2) Process ID: 24E003DC (3) Node: ZEUS Process name: "CLEAVER" (4) Terminal: VTA2195: TNA2170: (Host: 126.96.36.199 Port: 6789) (5) User Identifier: [DOC,CLEAVER] (6) Base priority: 4 (7) Default file spec: DISK1:[CLEAVER] (8) Number of Kthreads: 1 Devices allocated: ALPHAI$VTA2195: Process Quotas: (9) Account name: DOC CPU limit: Infinite Direct I/O limit: 1024 Buffered I/O byte count quota: 119616 Buffered I/O limit: 1024 Timer queue entry quota: 400 Open file quota: 299 Paging file quota: 100080 Subprocess quota: 30 Default page fault cluster: 64 AST quota: 798 Enqueue quota: 5000 Shared file limit: 0 Max detached processes: 0 Max active jobs: 0 Accounting information: (10) Buffered I/O count: 16424 Peak working set size: 13920 Direct I/O count: 12014 Peak virtual size: 185392 Page faults: 11113 Mounted volumes: 0 Images activated: 68 Elapsed CPU time: 0 00:04:18.55 Connect time: 0 00:08:22.76 Authorized privileges: NETMBX TMPMBX Process privileges: (11) GROUP may affect other processes in same group TMPMBX may create temporary mailbox OPER operator privilege NETMBX may create network device Process rights: (12) CLEAVER resource INTERACTIVE LOCAL System rights: SYS$NODE_ZEUS Auto-unshelve: on Image Dump: off Soft CPU Affinity: off Parse Style: Traditional Home RAD: 0 Scheduling class name: none Process Dynamic Memory Area (13) Current Size (Kb) 128.00 Current Size (Pagelets) 256 Free Space (Kb) 111.18 Space in Use (Kb) 16.81 Largest Var Block (Kb) 109.69 Smallest Var Block (bytes) 8 Number of Free Blocks 10 Free Blocks LEQU 64 Bytes 4 There is 1 process in this job: (14) CLEAVER (*)
A detached process is either interactive or noninteractive, depending
on the parent process. Either you or the operating system perform the
login, depending on the argument you provided to the DCL command RUN or
the Create Process system service ($CREPRC). (Both RUN and $CREPRC
execute the LOGINOUT.EXE image in SYS$SYSTEM.)
16.3 Using Subprocesses
The SPAWN command enables you to create a subprocess of your current process. Within this subprocess, you can interact with the system and log out of the subprocess to return to your parent process or switch between your parent process and subprocesses. Only one of your processes is executing at any time.
Each user on the system is represented by a job tree.
A job tree is a hierarchy of all your processes and subprocesses with
your main process at the top. A subprocess is dependent on the parent
process and is deleted when the parent process exits. By default, the
subprocess assumes the name of the parent process followed by an
underscore and a unique number. For example, if the parent process name
is DOUGLASS, the subprocesses are named DOUGLASS_1, DOUGLASS_2, and so
16.3.1 Using Subprocesses to Spawn Tasks
To interrupt a task, perform a second task, then return to the original
task, you can use Ctrl/Y to interrupt the first task, spawn a
subprocess to perform the second task, exit from the subprocess, and
then enter the CONTINUE command to return to the first task. By
default, when you create a subprocess, the parent process hibernates
and you are given control at DCL level within the subprocess. Your
default directory is the current directory of the parent process. For
example, if you press Ctrl/Y to interrupt an EVE editing session, enter
the CONTINUE command and press Ctrl/W to refresh the screen.
16.3.2 Using Subprocesses to Perform Multiple Tasks
To perform a second task while continuing to work on your original task, you can create the subprocess with the SPAWN/NOWAIT command. SPAWN/NOWAIT generates a noninteractive, batch-like subprocess and is used to execute only commands that do not require input.
Because both the parent and the subprocess are executing concurrently, both attempt to control the terminal. To prevent conflicts, also specify the following:
When you specify the /INPUT qualifier of the SPAWN command, the
subprocess is created as a noninteractive process that exits upon
encountering a severe error or an end-of-file indicator. At DCL level,
Ctrl/Z is treated as an end-of-file indicator.
16.3.3 Creating a Subprocess
Because each process you create is unique, commands executed in one process do not usually affect any other process. However, because control of the terminal passes between processes, commands that affect the terminal characteristics (for example, SET TERMINAL) affect any process controlling that terminal. For example, if one process inhibits echoing and exits without restoring it, echoing remains inhibited for the next process that gains control of the terminal. Reset any altered terminal characteristics with the SET TERMINAL command.
In the following example, a user interrupts a command image (the TYPE command) by pressing Ctrl/Y, spawns a subprocess, exits from the subprocess, and returns to the original process:
$ TYPE MICE.TXT Once the weather turns cold, mice may find a crack in the foundation and enter your house. They are looking for food and shelter from the harsh weather ahead. . . . [Ctrl/Y] $ SPAWN %DCL-S-SPAWNED, process DOUGLASS_1 spawned %DCL-S-ATTACHED, terminal now attached to process DOUGLASS_1 $ MAIL MAIL> . . . MAIL> EXIT $ LOGOUT Process DOUGLASS_1 logged out at 31-DEC-1999 12:42:12.46 %DCL-S-RETURNED, control returned to process DOUGLASS $ CONTINUE Once inside, they may gnaw through electrical wires and raid your food. Because mice reproduce so quickly, what started as one or two mice can quickly become an invasion. If you seal the cracks and holes on the exterior of your foundation, you can prevent these rodents from ever getting in.
To exit from a subprocess created by the SPAWN command, use one of the following commands:
The following example shows how to exit from the subprocess DOUGLASS_1 and attach to the process DOUGLASS:
$ ATTACH DOUGLASS %DCL-S-RETURNED, control returned to process DOUGLASS $ SHOW PROCESS 11-DEC-2002 10:34:58.50 User: DOUGLASS Process ID: 2061C478 Node: ALPHAI Process name: "DOUGLASS" Terminal: VTA2195: TNA2170: (Host: 188.8.131.52 Port: 6789) User Identifier: [DOC,DOUGLASS] Base priority: 4 Default file spec: DISK1:[DOUGLASS] Number of Kthreads: 1 Devices allocated: ALPHAI$VTA2195: Soft CPU Affinity: off
The subprocess context is the environment that the subprocess inherits from the parent process. By default, a subprocess inherits the following items: defaults, privileges, symbols, logical names, control characters, message format, verification state, and key definitions. Collectively, these items create an environment for the subprocess.
The following items are not inherited from parent processes:
You can use the following SPAWN command qualifiers to prevent the subprocess from inheriting a number of these items:
|SPAWN Command Qualifier||Items Inhibited or Changed|
|/CARRIAGE_CONTROL, /PROMPT||DCL prompt|
|/NOCLI||CLI (command language interpreter; DCL by default)|
Because copying logical names and symbols to a subprocess can be time-consuming (a few seconds), you may want to use the /NOLOGICAL_NAMES and /NOSYMBOL qualifiers to the SPAWN command unless you plan to use the logical names or symbols in the subprocess. If you use subprocesses frequently, the ATTACH command provides the most efficient way to enter and exit a subprocess. This method allows you to transfer control quickly between the parent process and subprocess rather than repeatedly waiting for the system to create a new subprocess for you.