public static void ChangePriority(string Name, string Priority) { int NewPriority = 0; if (!int.TryParse(Priority, out NewPriority)) { Console.WriteLine("Podana wartosc nie jest liczba."); return; } if (NewPriority >= 0 && NewPriority <= 7) { PCB pcb = PCB.GetPCB(Name); if (pcb != null) { pcb.CurrentPriority = NewPriority; pcb.StartPriority = NewPriority; pcb.WaitingForProcessorTime = 1; Console.WriteLine("Ustawiono nowy priorytet (" + NewPriority + ") dla procesu " + Name + "."); } } else { Console.WriteLine("Priorytet procesu musi miescic sie w zakresie od 0 do 7."); } }
public static void ResumeProcess(string Name) { PCB pcb = PCB.GetPCB(Name); if (pcb != null) { pcb.StopWaiting(); } }
public static void SleepProcess(string Name) { PCB pcb = PCB.GetPCB(Name); if (pcb != null) { pcb.WaitForSomething(); } }
public static void ShowPCB(string Name) { PCB pcb = PCB.GetPCB(Name); if (pcb != null) { pcb.PrintAllFields(); } }
public static void StopProcess(string Name) { PCB pcb = PCB.GetPCB(Name); if (pcb != null) { pcb.TerminateProcess(ReasonOfProcessTerminating.UserClosed); } }
public static PCB CreateIdleProcess() { Console.WriteLine("Tworzenie procesu bezczynnosci systemu..."); PCB Idle = new PCB("ProcesBezczynnosci", 7, "idle.txt", SourceOfCode.WindowsDisc); Idle._PID = 0; Idle.StartPriority = 8; Idle.CurrentPriority = 8; Idle.RunNewProcess(); Idle.RunReadyProcess(); return(Idle); }
public static void RunNewProcess(string Name) { if (Name == "-all") { PCB.RunAllNewProcesses(); } else { PCB pcb = PCB.GetPCB(Name); if (pcb != null) { pcb.RunNewProcess(); } } }
public void Lock(PCB Proces) { if (Check()) { proces = Proces; this.Name = proces.Name; open = 1; proces.WaitForSomething(); Proces.InstructionCounter--; } else { waiting.Add(Proces); Proces.WaitForSomething(); Proces.InstructionCounter--; } }
public void Unlock(string name) { if (!Check()) { if (waiting.Count() > 0) { if (!Check(name)) { foreach (var i in waiting) { if (name == i.Name) { i.StopWaiting(); waiting.Remove(i); break; } } } else { proces.StopWaiting(); proces = waiting[0]; waiting.Remove(proces); this.Name = proces.Name; } } else if (waiting.Count() == 0) { if (Check(name)) { proces.StopWaiting(); open = 0; } } } }
/// <summary> /// Zamyka proces (stan = terminated) /// </summary> /// <param name="ClosingProcess">Proces zamykający (tylko, jesli przyczyna = KilledByOther, w p.p. null)</param> /// <returns> /// 0 - zamknięto proces /// 1 - proces oczekuje na zamkniecie /// 2 - jeśli zamykany przez inny proces, nie podano procesu zamykającego /// 3 - próba zamknięcia procesu systemowego /// </returns> public int TerminateProcess(ReasonOfProcessTerminating Reason, PCB ClosingProcess = null, int ExitCode = 0) { if (Reason == ReasonOfProcessTerminating.KilledByOther && ClosingProcess == null) { Console.WriteLine("Blad zamykania procesu: nie podano procesu zamykajacego."); return(2); } if (PID == 0) { Console.WriteLine("Nie mozna zamknac procesu systemowego."); return(3); } string ReasonString = "(brak powodu)"; switch (Reason) { case ReasonOfProcessTerminating.Ended: ReasonString = "Proces sie zakonczyl."; break; case ReasonOfProcessTerminating.ThrownError: ReasonString = "Wystapil blad w procesie."; break; case ReasonOfProcessTerminating.UserClosed: ReasonString = "Proces zostal zakmniety przez uzytkownika."; break; case ReasonOfProcessTerminating.CriticalError: ReasonString = "Program spowodowal wystapienie bledu krytycznego i zostal zamkniety przez system."; break; case ReasonOfProcessTerminating.KilledByOther: ReasonString = "Proces zostal zamkniety przez proces " + ClosingProcess.ToString() + "."; break; case ReasonOfProcessTerminating.ClosingSystem: ReasonString = "Proces zostal zamkniety z powodu zamykania systemu."; break; } if (State == ProcessState.Running) { State = ProcessState.Terminated; CPU.Scheduler.GetInstance.RemoveProcess(this); Console.WriteLine("Zakonczono proces " + this.ToString() + "."); Console.WriteLine("Powod zamkniecia: " + ReasonString); Console.WriteLine("Kod wyjscia procesu: " + ExitCode.ToString()); this.RemoveProcess(); return(0); } else { WaitingForStopping = true; Console.WriteLine("Oczekiwanie na zamkniecie procesu: " + this.ToString() + "."); Console.WriteLine("Proces zostanie zamkniety po przejsciu do stanu Running."); Console.WriteLine("Kod wyjscia procesu: " + ExitCode.ToString()); Console.WriteLine("Powod zamkniecia: " + ReasonString); //Zablokuj proces zamykający if (Reason == ReasonOfProcessTerminating.KilledByOther) { this.ClosingProcess = ClosingProcess; StopperLock.Lock(ClosingProcess); } return(1); } }
public static void ShowAllProcesses() { PCB.PrintAllPCBs(); }