Пример #1
0
        public void CreateProcess(string processName, List <SyntaxNode> program, Priority priority = Priority.Normal)
        {
            CheckChannel();
            var findInProcess = ProcessList.Find(t => t.Name == processName);
            var findInSuspend = SuspendedList.Find(t => t.Name == processName);

            if (findInProcess == null && findInSuspend == null)
            {
                var process = new Process()
                {
                    Name       = processName,
                    Program    = program,
                    Priority   = priority,
                    State      = State.Created,
                    CpuState   = new CpuState(1048576),
                    CreateTime = Time
                };
                ProcessList.Add(process);
                SortList();
                AllocateMemory(process.Name);
                OnProcessCreate(process);
            }
            else
            {
                throw new ProcessConflictException()
                      {
                          Name = processName
                      };
            }
        }
Пример #2
0
        public void KillProcess(string processName)
        {
            var find = ProcessList.Find(t => t.Name == processName);

            if (find == null)
            {
                find = SuspendedList.Find(t => t.Name == processName);
                if (find == null)
                {
                    throw new ProcessNotExistException()
                          {
                              Name = processName
                          };
                }
                else
                {
                    SuspendedList.Remove(find);
                    OnProcessKilled(find);
                }
            }
            else
            {
                ProcessList.Remove(find);
                OnProcessKilled(find);
            }
        }
Пример #3
0
        public void AllocateMemory(string processName)
        {
            var process = ProcessList.Find(t => t.Name == processName);

            if (process == null)
            {
                process = SuspendedList.Find(t => t.Name == processName);
            }
            if (process == null)
            {
                throw new ProcessNotExistException();
            }

            var processSize = process.MemorySize;
            var hole        = FindHole(processSize);

            process.Memory = new MemoryAllocation(hole.Item1, hole.Item2, MemoryAllocationType.Process);
        }
Пример #4
0
        public void ResumeProcess(string processName)
        {
            var find = SuspendedList.Find(t => t.Name == processName);

            if (find != null)
            {
                SuspendedList.Remove(find);
                find.State = State.Ready;
                ProcessList.Add(find);
                OnProcessStateChange(find, State.Suspended);
            }
            else
            {
                throw new ProcessNotExistException()
                      {
                          Name = processName
                      };
            }
        }