home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / dtx9202 / borhot / psp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-28  |  1.5 KB  |  46 lines

  1. /* ------------------------------------------------------ */
  2. /*                      PSP.C                             */
  3. /*   How to Get the Name of a Spawned Program's Parent    */
  4. /*            (c) 1990 Borland International              */
  5. /*                 All rights reserved.                   */
  6. /* ------------------------------------------------------ */
  7. /*  veröffentlicht in: DOS toolbox 2'92                   */
  8. /* ------------------------------------------------------ */
  9.  
  10. #include <stdio.h>        // for putchar()
  11. #include <dos.h>          // for MK_FP
  12.  
  13. typedef unsigned SEG;
  14.  
  15. extern SEG _psp;
  16.  
  17. // ------------------------------------------------------- *
  18. int main (void) {
  19.   SEG  far * pspparent;    // Segment of parent PSP
  20.   SEG  far * envparent;    // Segment of parent environment
  21.   char far *who;           // Char ptr to name of parent
  22.  
  23.   // Get segment and environment of parent PSP
  24.  
  25.   pspparent = (SEG far*) MK_FP(_psp, 0x16);
  26.   envparent = (SEG far*) MK_FP(*pspparent, 0x2C);
  27.  
  28.   // Initialize parent process name pointer
  29.  
  30.   who = (char far*) MK_FP(*envparent, 0x00);
  31.  
  32.   // Find the end of the environment. The environment is
  33.   // terminated by two '\0' characters
  34.  
  35.   while (!((who [0] == '\0') && (who [1] == '\0'))) who++;
  36.  
  37.   // Point at the parent process name and display it.
  38.  
  39.   who += 4;
  40.   while (who [0] != '\0') putchar (*who++);
  41.   return 0;
  42. }  // end of main()
  43. /* ------------------------------------------------------ */
  44. /*                   Ende von PSP.C                       */
  45.  
  46.