Exemplo n.º 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
                      };
            }
        }
Exemplo n.º 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);
            }
        }
 public void OpenFolder(int id)
 {
     lock (_lock)
     {
         var p = ProcessList.Find(process => process.Id == id);
         if (p != null)
         {
             Process.Start("explorer.exe", "/select, " + p.FilePath);
         }
     }
 }
 public void Remove(int id)
 {
     lock (_lock)
     {
         var p = ProcessList.Find(process => process.Id == id);
         if (p == null)
         {
             return;
         }
         p.Kill();
         ProcessList.Remove(p);
     }
 }
Exemplo n.º 5
0
        public override Result evaluate()
        {
            ProcessList.Sort(new EntryPointComparator());
            List <Process> activeprocesses = new List <Process>();
            int            currentTime     = 0;

            do
            {
                bool done = false;
                for (int i = 0; i < ProcessList.Count; i++)
                {
                    done = false;
                    if (currentTime == ProcessList[i].EntryMoment)
                    {
                        activeprocesses.Add(ProcessList[i]);
                        activeprocesses.Sort(new TimeRemainingComparator());
                    }
                    done = currentTime > ProcessList[i].EntryMoment;
                }
                if (activeprocesses.Count > 0)
                {
                    activeprocesses[0].TimeLeft -= 1;
                }
                currentTime++;
                if (activeprocesses.Count > 0 && activeprocesses[0].TimeLeft == 0)
                {
                    Process temp = ProcessList.Find((e) =>
                    {
                        return(e.Equals(activeprocesses[0]));
                    });
                    ProcessList.Find((e) =>
                    {
                        return(e.Equals(activeprocesses[0]));
                    }).WaitingTime = currentTime - temp.Duration - temp.EntryMoment;
                    activeprocesses.RemoveAt(0);
                    activeprocesses.Sort(new TimeRemainingComparator());
                }
                if (activeprocesses.Count == 0 && done)
                {
                    break;
                }
            } while (currentTime < 1000000);
            List <int> wait = new List <int>();

            foreach (Process i in ProcessList)
            {
                wait.Add(i.WaitingTime);
            }
            return(new Result(wait, Name));
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        public void SuspendProcess(string processName)
        {
            var find        = ProcessList.Find(t => t.Name == processName);
            var beforeState = find.State;

            if (find != null)
            {
                ProcessList.Remove(find);
                find.State = State.Suspended;
                SuspendedList.Add(find);
                OnProcessStateChange(find, beforeState);
            }
            else
            {
                throw new ProcessNotExistException()
                      {
                          Name = processName
                      };
            }
        }
Exemplo n.º 8
0
        public void ScheduleProcess(string processName)
        {
            if (ProcessCount == ChannelCount)
            {
                ProcessList.FindAll(t => t.State == State.Terminated).ForEach(t => KillProcess(t.Name));
            }

            var find = ProcessList.Find(t => t.State == State.Created || t.Name == processName);

            if (find != null)
            {
                find.State = State.Ready;
                OnProcessStateChange(find, State.Created);
            }
            else
            {
                throw new ProcessNotExistException()
                      {
                          Name = processName
                      };
            }
        }