public void Tick() { if (CurrentProcess == null || CurrentProcess.Quanta == 0 || CurrentProcess == IdleProcess) { CurrentProcess = SwitchToNextProcess(); } Stream codeStream = GetMemoryStream(CurrentProcess.Code); var codeReader = new CodeReader(codeStream); var instruction = codeReader[Ip]; if (instruction != null) { Execute(instruction); } else { foreach (var page in CurrentProcess.PageTable) { Ram.Free(page); } CurrentProcess.IsRunning = false; CurrentProcess = null; } TickSleepTimer(); ReadTerminal(); WriteTerminal(); TickCount++; }
public void TerminateProcess(uint pId, uint exitCode) { var process = _processes[pId]; foreach (var page in process.PageTable) { Ram.Free(page); } process.ExitCode = exitCode; process.IsRunning = false; }
public void Exit(uint exitCode) { CurrentProcess.ExitCode = exitCode; CurrentProcess.IsRunning = false; foreach (var page in CurrentProcess.PageTable) { Ram.Free(page); } CurrentProcess = null; }
public void Free(uint offset) { var page = CurrentProcess.PageTable.Find(x => x.Offset == offset); if (page != null) { foreach (var p in page.Pages) { Ram.Free(p); } CurrentProcess.PageTable.Free(page); } }
public void Free() { var ram = new Ram(2, 1); var pcb = new ProcessContextBlock { Id = 1 }; var frame = ram.Allocate(pcb); Assert.That(frame, Is.Not.Null); frame = ram.Allocate(pcb); Assert.That(frame, Is.Not.Null); ram.Free(frame); frame = ram.Allocate(pcb); Assert.That(frame, Is.Not.Null); }