Jump to content

DosKillProcess: Difference between revisions

From EDM2
Ak120 (talk | contribs)
No edit summary
Line 1: Line 1:
==DosKillProcess==
===Syntax===
===Syntax===
 
rc = DosKillProcess( ''ulAction'', ''pid'' );
rc = DosKillProcess( ''ulAction'', ''pid'' );


===Parameters===
===Parameters===
 
;ULONG ''ulAction'' (input)
; ULONG ''ulAction'' (input)
:Sets the processes to be terminated. Values are:   
: Sets the processes to be terminated. Values are:   
  Value  Name            Description
  Value  Name            Description
  0      DKP_PROCESSTREE  Kill the process and all its descendant processes.
  0      DKP_PROCESSTREE  Kill the process and all its descendant processes.
Line 17: Line 12:
                         (2).
                         (2).
  1      DKP_PROCESS      Any process and only that process.
  1      DKP_PROCESS      Any process and only that process.
; PID ''pid'' (input)
;PID ''pid'' (input): Process ID for the process to be killed.
: Process ID for the process to be killed.


===Returns===
===Returns===
  APIRET    rc
  APIRET    rc
  0        NO_ERROR
  0        NO_ERROR
Line 31: Line 23:


===Include Info===
===Include Info===
  #define INCL_DOSPROCESS
  #define INCL_DOSPROCESS
  #include <os2.h>
  #include <os2.h>


===Usage Explanation===
===Usage Explanation===
DosKillProcess is used to kill a process by its process ID. What happens is that a KILLPROCESS exception is sent to the given process or group of processes. This by default will write all file buffers, and handles opened by the process will be closed. It is possible to intercept the exception with the use of DosSetExceptionHandler, and then the process will do its own nice exit and call DosExit. If another process has issued a DosWaitChild for a process terminated it will get termination code "Unintercepted DosKillProcess" (TC_KILLPROCESS = 3). ERROR_ZOMBIE_PROCESS indicates that the specified process has ended, but its parent has not yet issued DosWaitChild to get its return code.
DosKillProcess is used to kill a process by its process ID. What happens is that a KILLPROCESS exception is sent to the given process or group of processes. This by default will write all file buffers, and handles opened by the process will be closed. It is possible to intercept the exception with the use of DosSetExceptionHandler, and then the process will do its own nice exit and call DosExit. If another process has issued a DosWaitChild for a process terminated it will get termination code "Unintercepted DosKillProcess" (TC_KILLPROCESS = 3). ERROR_ZOMBIE_PROCESS indicates that the specified process has ended, but its parent has not yet issued DosWaitChild to get its return code.
===Relevant Structures===
===Gotchas===


===Sample Code===
===Sample Code===
 
<code>
  #define INCL_DOSPROCESS
  #define INCL_DOSPROCESS
  #include <os2.h>
  #include <os2.h>
Line 58: Line 44:
     /* There is a problem killing the process */
     /* There is a problem killing the process */
  }
  }
</code>


===See Also===
===See Also===
*[[DosExecPgm]]
*[[DosWaitChild]]
*[[DosExit]]
*[[DosStartSession]]


[[OS2 API:CPI:DosExecPgm|DosExecPgm]], [[OS2 API:CPI:DosWaitChild|DosWaitChild]], [[OS2 API:CPI:DosExit|DosExit]], [[OS2 API:CPI:DosStartSession|DosStartSession]]
[[Category:Dos]]
 
[[Category:The OS/2 API Project]]

Revision as of 03:48, 4 January 2017

Syntax

rc = DosKillProcess( ulAction, pid );

Parameters

ULONG ulAction (input)
Sets the processes to be terminated. Values are:
Value  Name             Description
0      DKP_PROCESSTREE  Kill the process and all its descendant processes.
                        Must be either the current process or it must
                        have been created by the current process using
                        DosExecPgm with ulFlagS set to EXEC_ASYNCRESULT
                        (2).
1      DKP_PROCESS      Any process and only that process.
PID pid (input)
Process ID for the process to be killed.

Returns

APIRET    rc
0         NO_ERROR
13        ERROR_INVALID_DATA
217       ERROR_ZOMBIE_PROCESS
303       ERROR_INVALID_PROCID
305       ERROR_NOT_DESCENDANT

Include Info

#define INCL_DOSPROCESS
#include <os2.h>

Usage Explanation

DosKillProcess is used to kill a process by its process ID. What happens is that a KILLPROCESS exception is sent to the given process or group of processes. This by default will write all file buffers, and handles opened by the process will be closed. It is possible to intercept the exception with the use of DosSetExceptionHandler, and then the process will do its own nice exit and call DosExit. If another process has issued a DosWaitChild for a process terminated it will get termination code "Unintercepted DosKillProcess" (TC_KILLPROCESS = 3). ERROR_ZOMBIE_PROCESS indicates that the specified process has ended, but its parent has not yet issued DosWaitChild to get its return code.

Sample Code

#define INCL_DOSPROCESS
#include <os2.h>

RESULTCODES ReturnCodes

/* Start a process with DosExecPgm */
/* DosExecPgm(..,.., EXEC_ASYNC,..,.., &ReturnCodes,..); */

/* Kill the process started */
if(DosKillProcess(DKP_PROCESS,ReturnCodes.codeTerminate))
{
    /* There is a problem killing the process */
}

See Also