 |
» |
|
 |
|
 |

Copyright (c) Digital Equipment Corporation 1985. All rights reserved
OVERVIEW:
This example program will use SYS$GETJPI to retrieve the user
identification code (UIC) of the running process, then use that
information in SYS$CREPRC to create a detached process.
CAUTION: This sample program has been tested using PL/I V2.3 on VAX/VMS
V4.1. However, we cannot guarantee its effectiveness because of the
possibility of error in transmitting or implementing it. It is meant to be
used as a template for writing your own program, and it may require
modification for use on your system.
The length of this article is about 145 lines.
PROGRAM EXAMPLE:
/* The first program is the main program. You'll find a program in the
FOOTNOTE below that is to be run by the detached process. To run the
example, execute the following DCL commands after both programs have
been entered into files.
$ PLI CREPRC
$ LINK CREPRC
$ PLI DETACH
$ LINK DETACH
$ RUN CREPRC
It is assumed that the main program will be in a file called CREPRC.PLI
and the detached image will be in a file called DETACH.PLI */
ST: PROCEDURE OPTIONS(MAIN);
%INCLUDE SYS$CREPRC;
%INCLUDE SYS$DELPRC;
%INCLUDE SYS$GETJPI;
%INCLUDE SYS$WAITFR;
%INCLUDE $JPIDEF;
%INCLUDE $STSDEF;
DCL PIDADR FIXED BIN(31);
DCL PID_HEX CHARACTER(8);
DCL DATA CHARACTER(1);
DCL UIC FIXED BIN(31);
DCL EFN FIXED BINARY(31) INIT(3);
DCL MASK BIT(32) INIT('00000000000000000000000000000100'B);
/* Declare item list structure for $GETJPI */
DCL 01 ITEMLST,
02 SIZE FIXED BIN(15),
02 CODE FIXED BIN(15),
02 UIC POINTER,
02 UICL FIXED BIN(31),
02 END FIXED BIN(31);
DCL OTS$CVT_L_TZ EXTERNAL ENTRY
(FIXED BIN(31), /* VALUE */
CHARACTER (*), /* OUT-STRING */
ANY, /* INT-DIGITS */
ANY) /* VALUE-SIZE */
OPTIONS(VARIABLE) RETURNS (FIXED BIN(31));
/* Initialize the item list structure */
ITEMLST.SIZE = 4;
ITEMLST.CODE = JPI$_UIC;
ITEMLST.UIC = ADDR(UIC);
ITEMLST.UICL = 0;
ITEMLST.END = 0;
/* Call $GETJPI and wait for it to complete */
STS$VALUE = SYS$GETJPI(EFN,,,ITEMLST,,,);
IF ^STS$SUCCESS THEN SIGNAL VAXCONDITION(STS$VALUE);
STS$VALUE = SYS$WAITFR(EFN);
IF ^STS$SUCCESS THEN SIGNAL VAXCONDITION(STS$VALUE);
/* Create a detached process. Note that the image to run is called
'DETACH'. It must be an executable image in the same directory
as this program is run in. If not, you must include a full file
specification in the second argument. For testing purposes we
recommend you use the program 'DETACH.PLI' supplied with this
article (see the FOOTNOTE below) */
STS$VALUE = SYS$CREPRC(PIDADR,
'DETACH',
'NLA0:',
'NLA0:',
'NLA0:' , , ,
'BONG0' , ,
UIC, , );
IF ^STS$SUCCESS THEN SIGNAL VAXCONDITION(STS$VALUE);
/* Convert the PID to a Hex ASCII string for output */
STS$VALUE = OTS$CVT_L_TZ(PIDADR, PID_HEX, , );
IF ^STS$SUCCESS THEN SIGNAL VAXCONDITION(STS$VALUE);
PUT SKIP LIST('Detach process BONGO created, the PID is: ',PID_HEX);
PUT SKIP LIST('Do a SHOW SYSTEM on another terminal to verify');
PUT SKIP LIST('Enter any character and the detached program will');
PUT SKIP LIST('be terminated by $DELPRC >>');
ON ENDFILE(SYSIN) GOTO FINISH;
GET LIST (DATA);
/* Delete the detached process now */
FINISH: STS$VALUE = SYS$DELPRC(PIDADR,);
IF ^STS$SUCCESS THEN SIGNAL VAXCONDITION(STS$VALUE);
PUT SKIP LIST('Process BONGO has been deleted');
END ST;
FOOTNOTE:
The following program is to be run by the detached process created by the
preceding sample program ('CREPRC'). It must be an executable image in
the same directory as 'CREPRC' is run in. If not, a full file specifica-
tion must be given.
ST: PROCEDURE OPTIONS(MAIN);
%INCLUDE $STSDEF;
%INCLUDE SYS$HIBER;
STS$VALUE = SYS$HIBER();
END ST;
|
buy online or call 1.800.AT.COMPAQ
|
|