[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

OpenVMS User's Manual


Previous Contents Index

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:


$ ! Initialize context symbol to get PID numbers
$ CONTEXT = ""
$ ! Write headings
$ WRITE SYS$OUTPUT "Process Name     PID"
$ !
$ GET_PID:
$ PID = F$PID(CONTEXT)
$ IF PID .EQS. "" THEN EXIT
$ WRITE SYS$OUTPUT F$GETJPI(PID,"PRCNAM"),"     ", F$GETJPI(PID,"PID")
$ GOTO GET_PID

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:


Process Name     PID
MARCHESAND     2CA0049C
TRACTMEN     2CA0043A
FALLON     2CA0043C
ODONNELL     2CA00453
PERRIN     2CA004DE
CHAMPIONS     2CA004E3

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:


$ ! Initialize context symbol to get PID numbers
$ CONTEXT = ""
$ ! Write headings
$ WRITE SYS$OUTPUT "Process Name     PID"
$ !
$ GET_PID:
$ PID = F$PID(CONTEXT)
$ IF PID .EQS. "" THEN EXIT
$ LINE = F$FAO("!16AS !12AS", F$GETJPI(PID,"PRCNAM"), F$GETJPI(PID,"PID"))
$ WRITE SYS$OUTPUT LINE
$ GOTO GET_PID

Now when you execute the procedure, the columns will align:


Process Name     PID
MARCHESAND       2CA0049C
TRACTMEN         2CA0043A
FALLON           2CA0043C
ODONNELL         2CA00453
PERRIN           2CA004DE
CHAMPIONS        2CA004E3

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).


$ ! Initialize context symbol to get PID numbers
$ CONTEXT = ""
$ ! Write headings
$ WRITE SYS$OUTPUT "Process Name     PID"
$ !
$ GET_PID:
$ PID = F$PID(CONTEXT)
$ IF PID .EQS. "" THEN EXIT
$ RECORD[0,16]:= 'F$GETJPI(PID,"PRCNAM")'
$ RECORD[17,12]:= 'F$GETJPI(PID,"PID")'
$ WRITE SYS$OUTPUT RECORD
$ GOTO GET_PID

This procedure produces the same type of formatted columns you created with the F$FAO function:


Process Name     PID
MARCHESAND       2CA0049C
TRACTMEN         2CA0043A
FALLON           2CA0043C
ODONNELL         2CA00453
PERRIN           2CA004DE
CHAMPIONS        2CA004E3

15.7 Manipulating Data Types

You can use the following lexical functions to convert data from strings to integers and from integers to strings:

F$CVSI Extracts bit fields from a character string and converts the result, as a signed value, to an integer
F$CVUI Extracts bit fields from a character string and converts the result, as an unsigned value, to an integer
F$INTEGER Converts a string expression to an integer
F$STRING Converts an integer expression to a string
F$TYPE Determines the data type of a symbol

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.


$ IF P1 .EQS. "" THEN INQUIRE P1 "Value to be converted"
$ GOTO CONVERT_'F$TYPE(P1)'
$
$ CONVERT_STRING:
$ WRITE SYS$OUTPUT "The string ''P1' is converted to ''F$INTEGER(P1)'"
$ EXIT
$
$ CONVERT_INTEGER:
$ WRITE SYS$OUTPUT "The integer ''P1' is converted to ''F$STRING(P1)'"
$ EXIT

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:


$ INQUIRE EXP "Enter integer expression"
$ RES = F$INTEGER('EXP')
$ WRITE SYS$OUTPUT "Result is",RES

The output from this command procedure would be as follows:


Enter integer expression: 9 + 7
Result is 16

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.

15.7.3 Determining Whether a Symbol Exists

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:


   .
   .
   .
$ IF F$TYPE(TEMP) .EQS. "" THEN TEMP = "YES"
$ IF TEMP .EQS. "YES" THEN GOTO TEMP_SEC
   .
   .
   .

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.


Chapter 16
Understanding Processes and Batch Jobs

A process is an environment created by the OpenVMS operating system that lets you interact with the system. A process can be a detached process (a process that is independent of other processes) or a subprocess (a process that is dependent on another process for its existence and resources). Your main process, also called your parent process, is a detached process. This chapter describes:

  • Interpreting your process context
  • Using subprocesses
  • Connecting to disconnected processes on virtual terminals
  • Working with batch jobs

How Processes Are Created

The system creates a process for you when you perform one of the following tasks:

  • Logging in
    The system creates a process for each interactive user.
  • Submitting a batch job
    The system creates a process for each batch job. When the batch job is completed, the system deletes the process.
  • Spawning a subprocess
    The system creates a process when you use the SPAWN command.
  • Running a program
    The system creates a process when you run a program using either the /DETACHED qualifier or the /UIC=uic qualifier.

16.1 Interpreting Your Process Context

Characteristics that a process uses, such as privileges, symbols, and logical names, form a process context. The system obtains the characteristics that are unique to your process from the user authorization file (UAF). The UAF lists those users permitted to access the system and defines the characteristics for each user's process. The system manager usually maintains the UAF. It is within your process that the system executes your programs (also called images or executable images) one at a time.

To display the process context for your current process, enter the SHOW PROCESS/ALL command.

The following example shows a process context:


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: 16.32.123.45 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 (*)

As you examine the example, note the following:

  1. Current date and time
    The date and time when the SHOW PROCESS/ALL command is executed.
  2. User name
    The user name assigned to the account that is associated with the process.
  3. Process identification (PID) number
    A unique number assigned to the process by the system. The SHOW PROCESS command displays the PID number as a hexadecimal number.
  4. Process name
    The name assigned to the process. Because process names are unique (within a specific UIC group), the first process logged in under an account is assigned the user name. Subsequent processes logged in under the same account are assigned the terminal name. You can change your process name with the DCL command SET PROCESS/NAME.
  5. User identification code (UIC)
    The group and member numbers (or letters) assigned to the account that is associated with the process (for example, [DOC,CLEAVER]). Part of your UIC identifies the group to which you belong. Within a group, users are allowed to share files or system resources more freely than between groups.
  6. Priority
    The current priority of the process.
  7. Default file specification
    The current device and directory. Change your current defaults with the DCL command SET DEFAULT.
  8. Process quotas
    The quotas (limits) associated with the process. Examine these quotas with the /QUOTAS or /ALL qualifiers of the SHOW PROCESS command.
  9. Accounting information
    The continuously updated account of the process' use of memory and CPU time. Examine this information with the /ACCOUNTING or /ALL qualifiers of the SHOW PROCESS command.
  10. Process privileges
    The privileges granted to your processes. Privileges restrict the performance of certain system activities to certain users. Examine your privileges with the /PRIVILEGES or /ALL qualifiers of the SHOW PROCESS command.
  11. Process rights
    System-defined identifiers that are used in conjunction with access control list (ACL) protection. Identifiers provide the means of specifying the users in an ACL. An ACL is a security tool that defines the kinds of access to be granted or denied to users of an object, such as a file, device, or mailbox.
  12. Process dynamic memory area
    The process' current use of dynamic memory. Dynamic memory is allocated by the system to an image when that image is executing. When that memory is no longer needed by one process, the system allocates it to another process. Examine this information with the /MEMORY or /ALL qualifiers of the SHOW PROCESS command.
  13. Processes in this tree
    A list of subprocesses belonging to the parent process. An asterisk (*) appears after the current process. Examine this list with the SHOW PROCESS/SUBPROCESSES or /ALL command.

16.2 Using Detached Processes

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 on.

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:

  • /OUTPUT qualifier
    Indicates that the subprocess should write output to a specified file rather than to the terminal
  • SPAWN command parameter or /INPUT qualifier
    Indicates that the subprocess should execute the specified commands rather than reading input from the terminal

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.

16.3.4 Exiting from a Subprocess

To exit from a subprocess created by the SPAWN command, use one of the following commands:

  • LOGOUT
    When you exit from a subprocess with the LOGOUT command, the subprocess is deleted (along with any subprocesses that it created) and you are returned to the parent process.
  • ATTACH
    When you exit from a subprocess with the ATTACH command, the subprocess hibernates and control of your terminal is transferred to the specified process. You must specify either a process name as a parameter to the ATTACH command or a process identification (PID) number as a value of the /IDENTIFIER qualifier of the ATTACH command.

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: 16.32.123.45 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

16.3.5 Subprocess Context

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:

  • Process identification (PID) number
    The system assigns each created subprocess a unique PID number.
  • Process name
    By default, the subprocess name consists of the name of the parent process followed by an underscore and an integer. Use the /PROCESS qualifier of the SPAWN command to specify a process name other than the default. A process name must be unique.
  • Created commands
    Commands that are defined by a parent process using the SET COMMAND command are not copied to a subprocess. To use a created command in a subprocess, you must use SET COMMAND to create that command for the subprocess.
  • Authorize privileges
    When you spawn to a subprocess, the process context contains the privileges of the parent process, not the privileges that you are authorized to enable. For example, if you plan to spawn to a subprocess while in Mail and to perform a privileged operation, you must first set the proper privilege in the parent process before you invoke Mail.

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)
/NOKEYPAD Keypad definitions
/NOLOGICAL_NAMES Logical names
/NOSYMBOL Symbols

The /SYMBOL and /LOGICAL_NAMES qualifiers do not affect system-defined symbols (such as $SEVERITY and $STATUS) or system-defined logical names (such as SYS$COMMAND and SYS$OUTPUT).

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.


Previous Next Contents Index