Jump to content

DosGetPPID: Difference between revisions

From EDM2
Ak120 (talk | contribs)
mNo edit summary
Ak120 (talk | contribs)
mNo edit summary
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
This call allows the caller to obtain the parent process ID for any process.
This call allows the caller to obtain the parent process ID for any process.
This function has been eliminated since OS/2 2.0


==Syntax==
==Syntax==
Line 11: Line 9:


==Return Code==
==Return Code==
rc (USHORT) - return
;rc (USHORT) - return:Return code descriptions are:
Return code descriptions are:
*0 NO_ERROR
* 0         NO_ERROR  
*303 ERROR_INVALID_PROCID
* 303       ERROR_INVALID_PROCID  


==Example Code==
==Bindings==
===C Binding===
===C===
<PRE>
<PRE>
#define INCL_DOSPROCESS
#define INCL_DOSPROCESS
Line 28: Line 25:
USHORT          rc;            /* return code */
USHORT          rc;            /* return code */
</PRE>
</PRE>
The following example demonstrates how to create a process, obtain process ID information, and kill a process. Process1 invokes process2 to run asynchronously. It obtains and prints some PID information, and then kills process2.  
 
===MASM===
<PRE>
EXTRN  DosGetPPID:FAR
INCL_DOSPROCESS    EQU 1
 
PUSH  WORD    PID          ;Process whose parent is wanted
PUSH@  WORD    PPID          ;Address to put parent's PID
CALL  DosGetPPID
 
Returns NONE
</PRE>
 
==Example==
The following example demonstrates how to create a process, obtain process ID information, and kill a process. Process1 invokes process2 to run asynchronously. It obtains and prints some PID information, and then kills process2.
<PRE>
<PRE>
/* ---- process1.c ---- */
/* ---- process1.c ---- */
Line 72: Line 83:
     printf("Process2 terminated by process1.\n");
     printf("Process2 terminated by process1.\n");
}
}
 
</PRE>
<PRE>
/* ---- process2.c ---- */
/* ---- process2.c ---- */
#define INCL_DOSPROCESS
#define INCL_DOSPROCESS
Line 92: Line 104:
</PRE>
</PRE>


===MASM Binding===
[[Category:Dos16]]
<PRE>
EXTRN  DosGetPPID:FAR
INCL_DOSPROCESS    EQU 1
 
PUSH  WORD    PID          ;Process whose parent is wanted
PUSH@  WORD    PPID          ;Address to put parent's PID
CALL  DosGetPPID
 
Returns NONE
</PRE>
==Related Functions==
*
 
[[Category:Dos]]

Latest revision as of 04:24, 26 January 2020

This call allows the caller to obtain the parent process ID for any process.

Syntax

DosGetPPID (PID, PPID)

Parameters

PID (USHORT) - input
The process ID of the process to find the parent PID.
PPID (PUSHORT) - output
Address of a word where the process ID of the parent of the indicated process is placed.

Return Code

rc (USHORT) - return
Return code descriptions are:
  • 0 NO_ERROR
  • 303 ERROR_INVALID_PROCID

Bindings

C

#define INCL_DOSPROCESS

USHORT  rc = DosGetPPID(PID, PPID);

USHORT           PID;           /* Process whose parent is wanted */
PUSHORT          PPID;          /* Address to put parent's PID */

USHORT           rc;            /* return code */

MASM

EXTRN  DosGetPPID:FAR
INCL_DOSPROCESS     EQU 1

PUSH   WORD    PID           ;Process whose parent is wanted
PUSH@  WORD    PPID          ;Address to put parent's PID
CALL   DosGetPPID

Returns NONE

Example

The following example demonstrates how to create a process, obtain process ID information, and kill a process. Process1 invokes process2 to run asynchronously. It obtains and prints some PID information, and then kills process2.

/* ---- process1.c ---- */
#define INCL_DOSPROCESS
#include <os2.h>
#define START_PROGRAM "process2.exe"   /* Program pointer */

main()
{
  CHAR          ObjFail [50];       /* Object name buffer */
  RESULTCODES   ReturnCodes;        /*
  PIDINFO       PidInfo;
  PID           ParentID;           /*
  USHORT        rc;

  printf("Process1 now running. \n");

  /** Start a child process. **/
  if(!(DosExecPgm(ObjFail,            /* Object name buffer */
                  sizeof(ObjFail),    /* Length of obj. name buffer */
                  EXEC_ASYNC,         /* Execution flag - asynchronous */
                  NULL,               /* No args. to pass to process2*/
                  NULL,               /* Process2 inherits process1's
                                          environment */
                  &ReturnCodes,       /* Ptr. to resultcodes struct. */
                  START_PROGRAM)))    /* Name of program file */
    printf("Process2 started. \n");

  /** Obtain Process ID information and print it **/
  if(!(rc=DosGetPID(&PidInfo)))       /* Process ID's (returned) */
    printf("DosGetPID: current process ID is %d; thread ID is %d; parent process ID is %d.\n",
            PidInfo.pid, PidInfo.tid, PidInfo.pidParent);
  if(!(rc=DosGetPPID(
           ReturnCodes.codeTerminate, /* Process whose parent is wanted */
           &ParentID)))               /* Address to put parent's PID */
    printf("Child process ID is %d; Parent process ID is %d.\n",
            ReturnCodes.codeTerminate, ParentID);

  /** Terminate process2 **/
  if(!(rc=DosKillProcess(DKP_PROCESSTREE,     /* Action code - kill process
                                                      and descendants */
                ReturnCodes.codeTerminate)))  /* PID of root of process tree */
    printf("Process2 terminated by process1.\n");
}
/* ---- process2.c ---- */
#define INCL_DOSPROCESS

#include <os2.h>

#define SLEEPTIME   500L
#define RETURN_CODE 0

main()
{
  printf("Process2 now running.\n");

  /* Sleep to allow process1 to kill it */
  DosSleep(SLEEPTIME);                /* Sleep interval */
  DosExit(EXIT_PROCESS,               /* Action Code */
          RETURN_CODE);               /* Result Code */
}