	PROGRAM suspend
C
C Program to implement the SUSPEND foreign command to suspend this or
C another process:
C
C+ SUSPEND
C
C The SUSPEND (foreign) command is used to suspend a process.
C Either another (separate) process may be suspended (by specifing either
C its process identification or its process name):
C
C		SUSPEND{/IDENTIFICATION=pid} {process-name}
C
C Or a process may suspend itself by doing SUSPEND and responding with
C a carriage return to the "Process?" prompt or by using:
C
C		SUSPEND .
C
C Define via:
C		SUSPEND :== $SUSPEND
C
C Any process may SUSPEND itself and any user can SUSPEND one of his/her
C subprocesses.  GROUP privilege is needed to SUSPEND detached processes
C of users with the same group number and WORLD privilege allows any
C process to be SUSPEND'ed.  Note that the process name can only be used
C when dealing with subprocesses or processes owned by users in the same
C group.
C
C-
C
	IMPLICIT INTEGER*4 (A - Z)
	PARAMETER DCL$_IVKEYW = '00038060'X	!Invalid keyword
C
	CHARACTER*80 command
	CHARACTER*16 qualifier
	INTEGER*4 pid,SYS$SUSPND
C
	DATA qualifier/'/IDENTIFICATION'/
C
C Get the command line after the verb (SUSPEND)
C
	status = LIB$GET_FOREIGN(command,'Process? ',length)
	IF (.NOT.status) CALL LIB$STOP(%VAL(status))
C
C Convert the entire command line to uppercase
C
	status = STR$UPCASE(command,command(1:length))
	IF (.NOT.status) CALL LIB$STOP(%VAL(status))
C
C Find out if the /IDENT... qualifier was used
C
	start = LIB$LOCC('/',command(1:length))
	IF (start.NE.0) THEN
	    endstr = LIB$LOCC('=',command(start:length))
	    IF (endstr.EQ.0) CALL LIB$STOP(%VAL(DCL$_IVKEYW))
C
C Check size and content of string for proper keyword
C
	    size = endstr-start
	    IF (size.LT.3) CALL LIB$STOP(%VAL(DCL$_IVKEYW))
	    IF (command(start:endstr-1).NE.qualifier(1:size))
	1	CALL LIB$STOP(%VAL(DCL$_IVKEYW))
C
C Get process id in hexadecimal
C
	    status = ots$cvt_tz_l(command(endstr+1:length),pid)
	    IF (.NOT.status) CALL LIB$STOP(%VAL(status))
C
C now suspend the requested process with the process id
C
	    status = SYS$SUSPND(pid,)
	    IF (.NOT.status) CALL LIB$STOP(%VAL(status))
C
	    ELSE
C
C No qualifier, try to get process name from command line
C
	    IF (length.NE.0) THEN
C
C First check for "process-name" as just a dot "."
C
		IF ((length.EQ.1).AND.(command(1:1).EQ.'.')) THEN
C
C For the command "SUSPEND .", suspend myself.
C
		    pid = 0
		    status = SYS$SUSPND(pid,)
		    IF (.NOT.status) CALL LIB$STOP(%VAL(status))
C
		    ELSE
C
C now suspend the requested process using the process name
C
		    pid = 0
		    status = SYS$SUSPND(pid,command(1:length))
		    IF (.NOT.status) CALL LIB$STOP(%VAL(status))
C
		    ENDIF
		ELSE
C
C Suspend self (no process id or process name given).
C
		pid = 0
		status = SYS$SUSPND(pid,)
		IF (.NOT.status) CALL LIB$STOP(%VAL(status))
C
		ENDIF
C
	    ENDIF
C
	END
