| 1 |
(* Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. *) |
| 2 |
(* This file is part of GNU Modula-2. |
| 3 |
|
| 4 |
GNU Modula-2 is free software; you can redistribute it and/or modify it under |
| 5 |
the terms of the GNU General Public License as published by the Free |
| 6 |
Software Foundation; either version 2, or (at your option) any later |
| 7 |
version. |
| 8 |
|
| 9 |
GNU Modula-2 is distributed in the hope that it will be useful, but WITHOUT ANY |
| 10 |
WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 |
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 |
for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public License along |
| 15 |
with gm2; see the file COPYING. If not, write to the Free Software |
| 16 |
Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *) |
| 17 |
MODULE testdiv ; |
| 18 |
|
| 19 |
FROM SYSTEM IMPORT ADDRESS ; |
| 20 |
FROM NumberIO IMPORT WriteCard ; |
| 21 |
FROM StrIO IMPORT WriteString, WriteLn ; |
| 22 |
FROM StrLib IMPORT StrLen ; |
| 23 |
|
| 24 |
|
| 25 |
CONST |
| 26 |
ClockFreq = 20 ; |
| 27 |
|
| 28 |
TYPE |
| 29 |
ProcType = (User, System) ; |
| 30 |
|
| 31 |
ProcStatus = (Runnable, WaitOnSem, WaitOnIO, Suspended, Killed, Sleeping) ; |
| 32 |
|
| 33 |
PtrToProcDes = POINTER TO ProcessDescriptor ; |
| 34 |
ProcessDescriptor = RECORD |
| 35 |
RightPtr : PtrToProcDes ; |
| 36 |
LeftPtr : PtrToProcDes ; |
| 37 |
RightRunPtr : PtrToProcDes ; |
| 38 |
LeftRunPtr : PtrToProcDes ; |
| 39 |
RightOwner : PtrToProcDes ; |
| 40 |
LeftOwner : PtrToProcDes ; |
| 41 |
Father : PtrToProcDes ; |
| 42 |
Sons : PtrToProcDes ; |
| 43 |
PPriority : CARDINAL ; (* 0..MaxPriority *) |
| 44 |
PQuanta : CARDINAL ; |
| 45 |
PMemorySize : CARDINAL ; |
| 46 |
PMemoryStart : ADDRESS ; |
| 47 |
PHeapSize : CARDINAL ; |
| 48 |
PHeapStart : ADDRESS ; |
| 49 |
PFreeMem : ADDRESS ; |
| 50 |
TimeSecs : CARDINAL ; |
| 51 |
PName : ARRAY [0..15] OF CHAR ; |
| 52 |
Process : ADDRESS ; |
| 53 |
PType : ProcType ; |
| 54 |
PCurrentStatus: ProcStatus ; |
| 55 |
PNextStatus : ProcStatus ; |
| 56 |
END ; |
| 57 |
|
| 58 |
|
| 59 |
PROCEDURE WriteProcess (p: PtrToProcDes) ; |
| 60 |
VAR |
| 61 |
i : CARDINAL ; |
| 62 |
BEGIN |
| 63 |
(* |
| 64 |
WriteString( p^.PName ) ; |
| 65 |
i := HIGH( p^.PName )-StrLen( p^.PName ) ; |
| 66 |
WHILE i>0 DO |
| 67 |
WriteString(' ') ; |
| 68 |
DEC( i ) |
| 69 |
END ; |
| 70 |
*) |
| 71 |
WITH p^ DO |
| 72 |
(* |
| 73 |
WriteCard( PMemorySize DIV 1024, 6 ) ; |
| 74 |
WriteString('k (') ; |
| 75 |
IF PMemorySize#0 |
| 76 |
THEN |
| 77 |
WriteCard( (PMemorySize - |
| 78 |
(CARDINAL(Process) - CARDINAL(PMemoryStart))) * 100 |
| 79 |
DIV PMemorySize, 3) |
| 80 |
ELSE |
| 81 |
WriteString(' 0') |
| 82 |
END ; |
| 83 |
WriteString('%) Pri') ; |
| 84 |
WriteCard( PPriority, 2 ) ; |
| 85 |
WriteCard( PQuanta, 3 ) ; |
| 86 |
WriteString(' ') ; |
| 87 |
WriteString(' ') ; |
| 88 |
WriteString(' ') ; |
| 89 |
*) |
| 90 |
WriteCard( (TimeSecs DIV ClockFreq) DIV (60*60), 2 ) ; (* Hours *) |
| 91 |
WriteString(':') ; |
| 92 |
WriteCard( ((TimeSecs DIV ClockFreq) DIV 60) MOD 60, 2) ; (* Minutes *) |
| 93 |
WriteString(':') ; |
| 94 |
WriteCard( (TimeSecs DIV ClockFreq) MOD 60, 2) (* Seconds *) |
| 95 |
END |
| 96 |
END WriteProcess ; |
| 97 |
|
| 98 |
|
| 99 |
VAR |
| 100 |
TimeSecs: CARDINAL ; |
| 101 |
p : PtrToProcDes ; |
| 102 |
BEGIN |
| 103 |
WriteProcess(p) |
| 104 |
END testdiv. |