SpKillProcess

From EDM2
Jump to: navigation, search

Flags a process to end, and returns the termination code to its parent (if any).

Syntax: success = spKillProcess ( [ [action] ,] pid )

Parameters: action – The value 'DKP_PROCESSTREE' is used to kill a process and all its descendant processes. The process must be either the current process, or it must have been directly created by the current process using DosExecPgm with a value of 2 (EXEC_ASYNCRESULT) for execFlag. 'DKP_PROCESS' is used to kill any process. This is the default value. Aliases for 'DKP_PROCESSTREE': 'PROCESSTREE', 'TREE', 'T'. Aliases for 'DKP_PROCESS': 'PROCESS', 'P' pid – The process id of the process to be terminated.

Returns:

0 – No error.
13 – Error, invalid data.
217 – Error, zombie process.
303 – Error, invalid process id
305 – Error, not descendant

Example Code:

/* killpid.cmd (spUtils Example Code) */
/* Kills the process with the pid passed as argument */

CALL RXFUNCADD 'spKillProcess','spUtils','spKillProcess'
PARSE ARG pid rest

IF spKillProcess(pid)\=0 THEN DO
   SAY 'Failed to kill pid ' || pid
END
ELSE DO
   SAY 'Pid ' || pid || ' has been killed.'
END