home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / program / compiler / m2posx14 / test / tvfork.mpp < prev   
Encoding:
Text File  |  1994-05-29  |  1.8 KB  |  83 lines

  1. MODULE tvfork;
  2. (* 19-Apr-94, Holger Kleinschmidt *)
  3. __IMP_SWITCHES__
  4. __DEBUG__
  5. #ifdef HM2
  6. #ifdef __LONG_WHOLE__
  7. (*$!i+: Modul muss mit $i- uebersetzt werden! *)
  8. (*$!w+: Modul muss mit $w- uebersetzt werden! *)
  9. #else
  10. (*$!i-: Modul muss mit $i+ uebersetzt werden! *)
  11. (*$!w-: Modul muss mit $w+ uebersetzt werden! *)
  12. #endif
  13. #endif
  14.  
  15. #ifdef MM2
  16. #warning *** tvfork does not work with MM2 and plain TOS
  17. #endif
  18.  
  19. #if (defined MM2) && (defined __DEBUG_CODE__)
  20. IMPORT Debug;
  21. #endif
  22.  
  23.  
  24. VAL_INTRINSIC
  25. CAST_IMPORT
  26. REGISTER_IMPORT
  27.  
  28. FROM SYSTEM IMPORT
  29. (* TYPE *) ADDRESS,
  30. (* PROC *) ADR;
  31.  
  32. IMPORT e;
  33.  
  34. FROM InOut IMPORT
  35. (* PROC *) WriteString, Write, Read, WriteLn, WriteInt;
  36.  
  37. FROM pOUT IMPORT
  38. (* PROC *) PutHex;
  39.  
  40. FROM proc IMPORT
  41. (* PROC *) vfork, Exit;
  42.  
  43. (*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
  44.  
  45. VAR
  46.   ch       : CHAR;
  47.   i1, i2   : INTEGER;
  48.   pid      : INTEGER;
  49.   spChild  : LONGCARD;
  50.   spParent : LONGCARD;
  51.  
  52. (*===========================================================================*)
  53.  
  54. BEGIN
  55.  i1  := 0; i2 := 0;
  56.  pid := vfork();
  57.  IF pid < 0 THEN
  58.    WriteString("Parent: vfork failed:");
  59.    WriteInt(e.errno, 3);
  60.    WriteLn;
  61.  ELSIF pid > 0 THEN
  62.    i1 := 33;
  63.    WriteString("Parent: vfork pid: ");
  64.    WriteInt(pid, 3); WriteLn;
  65.    GETLREG(15, spParent);
  66.    WriteString("Parent Stack: "); PutHex(spParent, 10); WriteLn;
  67.    WriteLn;
  68.  ELSE
  69.    i2 := 44;
  70.    WriteString("Child"); WriteLn;
  71.    GETLREG(15, spChild);
  72.    WriteString("Child Stack : "); PutHex(spChild, 10); WriteLn;
  73.    Exit(0);
  74.  END;
  75.  WriteString("Parent"); WriteLn;
  76.  WriteString("i1: "); WriteInt(i1, 3); WriteLn;
  77.  WriteString("i2: "); WriteInt(i2, 3); WriteLn;
  78.  WriteString("Stackdifferenz: ");
  79.  WriteInt(ABS(INT(spChild - spParent)), 10); WriteLn;
  80.  
  81.  Read(ch);
  82. END tvfork.
  83.