home *** CD-ROM | disk | FTP | other *** search
- MODULE tvfork;
- (* 19-Apr-94, Holger Kleinschmidt *)
- __IMP_SWITCHES__
- __DEBUG__
- #ifdef HM2
- #ifdef __LONG_WHOLE__
- (*$!i+: Modul muss mit $i- uebersetzt werden! *)
- (*$!w+: Modul muss mit $w- uebersetzt werden! *)
- #else
- (*$!i-: Modul muss mit $i+ uebersetzt werden! *)
- (*$!w-: Modul muss mit $w+ uebersetzt werden! *)
- #endif
- #endif
-
- #ifdef MM2
- #warning *** tvfork does not work with MM2 and plain TOS
- #endif
-
- #if (defined MM2) && (defined __DEBUG_CODE__)
- IMPORT Debug;
- #endif
-
-
- VAL_INTRINSIC
- CAST_IMPORT
- REGISTER_IMPORT
-
- FROM SYSTEM IMPORT
- (* TYPE *) ADDRESS,
- (* PROC *) ADR;
-
- IMPORT e;
-
- FROM InOut IMPORT
- (* PROC *) WriteString, Write, Read, WriteLn, WriteInt;
-
- FROM pOUT IMPORT
- (* PROC *) PutHex;
-
- FROM proc IMPORT
- (* PROC *) vfork, Exit;
-
- (*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
-
- VAR
- ch : CHAR;
- i1, i2 : INTEGER;
- pid : INTEGER;
- spChild : LONGCARD;
- spParent : LONGCARD;
-
- (*===========================================================================*)
-
- BEGIN
- i1 := 0; i2 := 0;
- pid := vfork();
- IF pid < 0 THEN
- WriteString("Parent: vfork failed:");
- WriteInt(e.errno, 3);
- WriteLn;
- ELSIF pid > 0 THEN
- i1 := 33;
- WriteString("Parent: vfork pid: ");
- WriteInt(pid, 3); WriteLn;
- GETLREG(15, spParent);
- WriteString("Parent Stack: "); PutHex(spParent, 10); WriteLn;
- WriteLn;
- ELSE
- i2 := 44;
- WriteString("Child"); WriteLn;
- GETLREG(15, spChild);
- WriteString("Child Stack : "); PutHex(spChild, 10); WriteLn;
- Exit(0);
- END;
- WriteString("Parent"); WriteLn;
- WriteString("i1: "); WriteInt(i1, 3); WriteLn;
- WriteString("i2: "); WriteInt(i2, 3); WriteLn;
- WriteString("Stackdifferenz: ");
- WriteInt(ABS(INT(spChild - spParent)), 10); WriteLn;
-
- Read(ch);
- END tvfork.
-