Document revision date: 19 July 1999 | |
Previous | Contents | Index |
This command procedure returns statistics about the current process, all processes in the group (if the current process has group privilege), and all processes on the system (if the current process has world privilege). This procedure illustrates use of the F$PID, F$EXTRACT, and F$GETJPI lexical functions.
$ ! $ ! Displays information about owner, group, or system processes. $ ! $ ! Turn off verification and save current settings $ SAVE_VERIFY_IMAGE = F$ENVIRONMENT("VERIFY_IMAGE") $ SAVE_VERIFY_PROCEDURE = F$VERIFY(0) $ CONTEXT = "" ! Initialize PID search context (1) $ ! $ ! Output header line. $ ! $ WRITE SYS$OUTPUT " PID Username Term Process " + - (2) "name State Pri Image" $ ! $ ! Output process information. $ ! $LOOP: $ ! $ ! Get next PID. If null, then done. $ ! $ PID = F$PID(CONTEXT) (3) $ IF PID .EQS. "" THEN GOTO DONE $ ! $ ! Get image file specification and extract the file name. $ ! $ IMAGNAME = F$GETJPI(PID,"IMAGNAME") (4) $ IMAGNAME = F$PARSE(IMAGNAME,,,"NAME","SYNTAX_ONLY") $ ! $ ! Get terminal name. If none, then describe type of process. $ ! $ TERMINAL = F$GETJPI(PID,"TERMINAL") (5) $ IF TERMINAL .EQS. "" THEN - TERMINAL = "-"+F$EXTRACT(0,3,F$GETJPI(PID,"MODE"))+"-" $ IF TERMINAL .EQS. "-INT-" THEN TERMINAL = "-DET-" $ IF F$GETJPI(PID,"OWNER") .NE. 0 THEN TERMINAL = "-SUB-" $ ! $ ! Get more information, put process line together, $ ! and output it. $ ! $ LINE = F$FAO("!AS !12AS !7AS !15AS !5AS !2UL/!UL !10AS", - (6) PID,F$GETJPI(PID,"USERNAME"),TERMINAL,- F$GETJPI(PID,"PRCNAM"),- F$GETJPI(PID,"STATE"),F$GETJPI(PID,"PRI"),- F$GETJPI(PID,"PRIB"),IMAGNAME) $ WRITE SYS$OUTPUT LINE $ GOTO LOOP $ ! $ ! Restore verification and exit. $ ! $DONE: $ SAVE_VERIFY_PROCEDURE = F$VERIFY(SAVE_VERIFY_PROCEDURE,SAVE_VERIFY_IMAGE) $ EXIT |
Notes for SYS.COM Command Procedure
Sample Execution for SYS.COM Command Procedure
$ @SYS |
PID Username Term Process name State Pri Image 00050011 NETNONPRIV -NET- MAIL_14411 LEF 9/4 MAIL 00040013 STOVE RTA6: STOVE LEF 9/4 00140015 MAROT -DET- DMFB0ACP HIB 9/8 F11BAC 00080016 THOMPSON -DET- MTA0ACP HIB 12/8 MTAAACP 00070017 JUHLES TTF1: JUHLES LEF 9/4 . . . 00040018 MARCO TTA2: MARCO HIB 9/4 RTPAD 0018001A VERN RTA3: VERN LEF 9/4 0033001B YISHA RTA7: YISHA CUR 4/4 0002004A SYSTEM -DET- ERRFMT HIB 12/7 ERRFMT |
This procedure returns information on all processes on the system. The
current process has world privilege.
C.5 GETPARMS.COM Command Procedure
This command procedure returns the number of parameters passed to a procedure. You can call GETPARMS.COM from another procedure to determine how many parameters were passed to the calling procedure.
$ ! Procedure to count the number of parameters passed to a command $ ! procedure. This number is returned as the global symbol PARMCOUNT. $ ! $ SAVE_VERIFY_IMAGE = F$ENVIRONMENT("VERIFY_IMAGE") (1) $ SAVE_VERIFY_PROCEDURE = F$VERIFY(0) $ ! $ IF P1 .EQS. "?" THEN GOTO TELL (2) $ ! $ ! Loop to count the number of parameters passed. Null parameters are $ ! counted until the last non-null parameter is passed. $ ! $ COUNT = 0 (3) $ LASTNONNULL = 0 $ LOOP: $ IF COUNT .EQ. 8 THEN GOTO END_COUNT $ COUNT = COUNT + 1 $ IF P'COUNT' .NES. "" THEN LASTNONNULL = COUNT $ GOTO LOOP $ ! $ END_COUNT: (4) $ ! $ ! Place the number of non-null parameters passed into PARMCOUNT. $ ! $ PARMCOUNT == LASTNONNULL $ ! $ ! Restore verification setting, if it was on, before exiting $ ! (5) $ SAVE_VERIFY_PROCEDURE = F$VERIFY(SAVE_VERIFY_PROCEDURE,SAVE_VERIFY_IMAGE) $ EXIT $ ! $ TELL: (6) $ TYPE SYS$INPUT This procedure counts the number of parameters passed to another procedure. This procedure can be called by entering the following string in any procedure: @GETPARMS 'P1 'P2 'P3 'P4 'P5 'P6 'P7 'P8 On return, the global symbol PARMCOUNT contains the number of parameters passed to the procedure. $ ! $ EXIT |
Notes for GETPARMS.COM Command Procedure
Sample Execution for GETPARMS.COM Command Procedure
The procedure SORTFILES.COM requires the user to pass three non-null parameters. The SORTFILES.COM procedure can contain the following lines:
$ @GETPARMS 'P1' 'P2' 'P3' 'P4' 'P5' 'P6' 'P7' 'P8' $ IF PARMCOUNT .NE. 3 THEN GOTO NOT_ENOUGH . . . $NOT_ENOUGH: $ WRITE SYS$OUTPUT - "Three non-null parameters required. Type SORTFILES HELP for info." $ EXIT |
The procedure SORTFILES.COM can be invoked as follows:
$ @SORTFILES DEF 4 Three non-null parameters required. Type SORTFILE HELP for info. |
For this procedure to be properly invoked --- that is, for the parameters that are passed to SORTFILES to be passed intact to GETPARMS for processing --- the symbols P1 to P8 must be enclosed in single quotation marks.
If the return value from GETPARMS is not 3, SORTFILES outputs an error
message and exits.
C.6 EDITALL.COM Command Procedure
This command procedure invokes the EDT editor repeatedly to edit a group of files with the same file type. This procedure illustrates how to use lexical functions to extract file names from columnar output. It also illustrates a way to redefine the input stream for a program invoked within a command procedure.
$ ! Procedure to edit all files in a directory with a $ ! specified file type. Use P1 to indicate the file type. $ ! $ ON CONTROL_Y THEN GOTO DONE ! Ctrl/Y action (1) $ ON ERROR THEN GOTO DONE $ ! $ ! Check for file type parameter. If one was entered, continue; $ ! otherwise, prompt for a parameter. $ ! $ IF P1 .NES. "" THEN GOTO OKAY (2) $ INQUIRE P1 "Enter file type of files to edit" $ ! $ ! List all files with the specified file type and write the DIRECTORY $ ! output to a file named DIRECT.OUT $ ! $ OKAY: $ DIRECTORY/VERSIONS=1/COLUMNS=1 - (3) /NODATE/NOSIZE - /NOHEADING/NOTRAILING - /OUTPUT=DIRECT.OUT *.'P1' $ IF .NOT. $STATUS THEN GOTO ERROR_SEC (4) $ ! $ OPEN/READ/ERROR=ERROR_SEC DIRFILE DIRECT.OUT (5) $ ! $ ! Loop to read directory file $ ! $ NEWLINE: (6) $ READ/END=DONE DIRFILE NAME $ DEFINE/USER_MODE SYS$INPUT SYS$COMMAND: ! Redefine SYS$INPUT $ EDIT 'NAME' ! Edit the file $ GOTO NEWLINE $ ! $ DONE: (7) $ CLOSE DIRFILE/ERROR=NOTOPEN ! Close the file $ NOTOPEN: $ DELETE DIRECT.OUT;* ! Delete temp file $ EXIT $ ! $ ERROR_SEC: $ WRITE SYS$OUTPUT "Error: ",F$MESSAGE($STATUS) $ DELETE DIRECT.OUT;* $ EXIT |
Notes for EDITALL.COM Command Procedure
Sample Execution for EDITALL.COM Command Procedure
$ @EDITALL DAT * . . . %DELETE-I-FILDEL, device:[directory]DIRECT.OUT;1 deleted (x blocks) |
The procedure EDITALL is invoked with P1 specified as .DAT. The
procedure creates a directory listing of all files in the default
directory whose file types are .DAT and invokes the editor to edit each
one. After you finish editing the last file with the file type .DAT,
the procedure deletes the temporary file DIRECT.OUT and displays an
informational message at your terminal.
C.7 MAILEDIT.COM Command Procedure
This command procedure invokes a text editor in the Mail utility.
$ ! Command procedure to invoke an editor for Mail. $ ! $ ! Inputs: $ ! $ ! P1 = Input file name. $ ! P2 = Output file name. $ ! $ ! If MAIL$EDIT is undefined, Mail will invoke the user's selected $ ! callable editor set by the mail SET EDITOR command. $ ! $ ! If MAIL$EDIT is defined to be a command procedure, Mail will create $ ! a subprocess to edit the mail, but any SET EDITOR command in Mail $ ! will override the definition of MAIL$EDIT for the remainder of that $ ! Mail session. $ ! $ ! Note that this procedure is run in the context of a subprocess. $ ! LOGIN.COM is not executed. However, all process logical names $ ! and DCL global symbols are copied. In particular, note that the $ ! user's individual definition of the symbol EDIT is used if there $ ! is one. Otherwise, the system default editor is used. $ ! $ ! The default directory is the same as the parent process $ ! $ DEFINE /USER SYS$INPUT 'F$TRNLNM("SYS$OUTPUT")' (1) $ IF P1 .EQS. "" THEN GOTO NOINPUT (2) $ EDIT /OUTPUT='P2' 'P1' (3) $ EXIT $NOINPUT: $ EDIT 'P2' (4) $ EXIT |
Notes for MAILEDIT.COM Command Procedure
$ RUN XYZ_EDITOR.EXE /INPUT= 'P1' /OUTPUT='P2' |
$ RUN XYZ_EDITOR.EXE /INPUT= 'P2' /OUTPUT='P2' |
Sample Execution for MAILEDIT.COM Command Procedure
$DEFINE MAIL$EDIT MAILEDIT.COM $MAIL MAIL> SHOW EDITOR Your editor is defined by the file MAILEDIT.COM. |
Provides a sample of a system-defined login command procedure that controls the terminal environment for an interactive user who creates, compiles, and executes FORTRAN programs. If a user logs in to a captive account where FORTUSER.COM is listed as the login command procedure, the user can execute only the commands accepted by FORTUSER.COM. This procedure also illustrates how to use lexical functions to step through an option table, comparing a user-entered command with a list of valid commands.
$ ! Procedure to create, compile, link, execute, and debug $ ! FORTRAN programs. Users can enter only the commands listed $ ! in the symbol OPTION_TABLE. $ SET NOCONTROL=Y (1) $ SAVE_VERIFY_IMAGE = F$ENVIRONMENT("VERIFY_IMAGE") $ SAVE_VERIFY_PROCEDURE = F$VERIFY(0) $ OPTION_TABLE = "EDIT/COMPILE/LINK/RUN/EXECUTE/DEBUG/PRINT/HELP/FILE/DONE/" (2) $ TYPE SYS$INPUT (3) VMS FORTRAN Command Interpreter Enter name of file with which you would like to work. $ ! $ ! Set up for initial prompt $ ! $ PROMPT = "INIT" (4) $ GOTO HELP ! Print the initial help message $ ! $ ! after the first prompting message, use the prompt: Command $ ! $ INIT: $ PROMPT = "GET_COMMAND" $ GOTO FILE ! Get initial file name $ ! $ ! Main command parsing routine. The routine compares the current $ ! command against the options in the option table. When it finds $ ! a match, it branches to the appropriate label. $ ! $ GET_COMMAND: $ ON CONTROL_Y THEN GOTO GET_COMMAND ! Ctrl/Y resets prompt (5) $ SET CONTROL=Y $ ON WARNING THEN GOTO GET_COMMAND ! If any, reset prompt $ INQUIRE COMMAND "Command" $ IF COMMAND .EQS. "" THEN GOTO GET_COMMAND $ IF F$LOCATE(COMMAND + "/", OPTION_TABLE) .EQ. F$LENGTH(OPTION_TABLE) - (6) THEN GOTO INVALID_COMMAND $ GOTO 'COMMAND' $ ! $ INVALID_COMMAND: (7) $ WRITE SYS$OUTPUT " Invalid command" $ ! $ HELP: (8) $ TYPE SYS$INPUT The commands you can enter are: FILE Name of FORTRAN program in your current default directory. Subsequent commands process this file. EDIT Edit the program. COMPILE Compile the program with FORTRAN. LINK Link the program to produce an executable image. RUN Run the program's executable image. EXECUTE Same function as COMPILE, LINK, and RUN. DEBUG Run the program under control of the debugger. PRINT Queue the most recent listing file for printing. DONE Return to interactive command level. HELP Print this help message. Enter Ctrl/Y to restart this session $ GOTO 'PROMPT' (9) $ EDIT: (10) $ DEFINE/USER_MODE SYS$INPUT SYS$COMMAND: $ EDIT 'FILE_NAME'.FOR $ GOTO GET_COMMAND $ COMPILE: $ FORTRAN 'FILE_NAME'/LIST/OBJECT/DEBUG $ GOTO GET_COMMAND $ LINK: $ LINK 'FILE_NAME'/DEBUG $ PURGE 'FILE_NAME'.*/KEEP=2 $ GOTO GET_COMMAND $ RUN: $ DEFINE/USER_MODE SYS$INPUT SYS$COMMAND: $ RUN/NODEBUG 'FILE_NAME' $ GOTO GET_COMMAND $ DEBUG: $ DEFINE/USER_MODE SYS$INPUT SYS$COMMAND: $ RUN 'FILE_NAME' $ GOTO GET_COMMAND $ EXECUTE: $ FORTRAN 'FILE_NAME'/LIST/OBJECT $ LINK/DEBUG 'FILE_NAME' $ PURGE 'FILE_NAME'.*/KEEP=2 $ RUN/NODEBUG 'FILE_NAME' $ GOTO GET_COMMAND $ PRINT: $ PRINT 'FILE_NAME' $ GOTO GET_COMMAND $ BADFILE: (11) $ WRITE SYS$OUTPUT "File must be in current default directory." $ FILE: $ INQUIRE FILE_NAME "File name" $ IF FILE_NAME .EQS. "" THEN GOTO FILE $ IF F$PARSE(FILE_NAME,,,"DIRECTORY") .NES. F$DIRECTORY() - (12) THEN GOTO BADFILE $ FILE_NAME = F$PARSE(FILE_NAME,,,"NAME") $ GOTO GET_COMMAND $ DONE: $ EXIT |
Notes for FORTUSER.COM Command Procedure
Sample Execution for FORTUSER.COM Command Procedure
The following example illustrates how to use this command procedure as a captive command procedure:
Username: CLASS30 Password: OpenVMS Version 7.1 OpenVMS FORTRAN Command Interpreter Enter name of file with which you would like to work. The commands you can enter are: FILE Name of FORTRAN program in your current default directory. Subsequent commands process this file. EDIT Edit the program. COMPILE Compile the program with VAX FORTRAN. LINK Link the program to produce an executable image. RUN Run the program's executable image. EXECUTE Same function as COMPILE, LINK and RUN. DEBUG Run the program under control of the debugger. PRINT Queue the most recent listing file for printing. DONE Return to interactive command level. HELP Print this help message. Enter Ctrl/Y to restart this session File name: AVERAGE Command: COMPILE Command: LINK Command: RUN Command: FILE File name: READFILE Command: EDIT |
This sample execution illustrates a session in which a user named CLASS30 logs in to the account controlled by the FORTUSER command procedure. The FORTUSER command procedure displays the commands the user is allowed to execute, as well as an instruction for restarting the session. Next, the user specifies the file AVERAGE, compiles, links, and runs it. Then, the user enters the FILE command to begin working on another file.
Previous | Next | Contents | Index |
privacy and legal statement | ||
6489PRO_056.HTML |