home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cenvi23.zip / PARENTS.CMD < prev    next >
OS/2 REXX Batch file  |  1994-10-04  |  1KB  |  42 lines

  1. EXTPROC CEnvi2
  2. /**********************************************************************
  3.  *** Parents.cmd - Display the current process id and name, and the ***
  4.  *** ver.1         tree of all ancestors of the current proc.       ***
  5.  **********************************************************************/
  6.  
  7. #include <DosCalls.lib>
  8.  
  9. // Build List of all running processes
  10. ProcessCount = BuildProcessList(PList);
  11. // starting with the current ID, show the process ID's of this and all parents
  12. ShowProcessInfo(GetMyID(),PList,ProcessCount,"Current Process ID");
  13.  
  14.  
  15. ShowProcessInfo(id,list,count,Text) // show this process information, and then call
  16. {                                   // recursively for parent
  17.    // find entry for this process ID
  18.    for ( i = 0; i < count; i++ ) {
  19.       if ( id == list[i].id ) {
  20.          // found this ID, so print it
  21.          printf("%s = %d, name = %s\n",Text,id,list[i].name);
  22.          // now try this function recursively on the parent ID
  23.          ShowProcessInfo(list[i].parent,list,count,"Parent Process ID");
  24.          break;
  25.       }
  26.    }
  27. }
  28.  
  29. GetMyID()   // get current process ID. Current ID is first UWORD32 in Process Info Block
  30. {
  31.    DosGetInfoBlocks(tid,pid);
  32.    return( peek(pid,UWORD32) );
  33. }
  34.  
  35. BuildProcessList(list) // build list of processes in list, and return number of processes running
  36. {
  37.    list = ProcessList();
  38.    assert( NULL != list );
  39.    return( 1 + GetArraySpan(list) );
  40. }
  41.  
  42.