示例#1
0
        // prebacujemo onaj proces koji je najvise koristio CPU
        public void RunningToReady()
        {
            int     cpu = 0;
            Process p   = null;

            foreach (Process pr in this.Running)
            {
                if (pr.CPU_usage >= cpu)
                {
                    cpu = pr.CPU_usage;
                    p   = pr;
                }
            }

            if (p == null || Running.Count == 0)
            {
                //Console.WriteLine("No running process.");
            }
            else
            {
                p.Status = "Ready";
                Running.Remove(p);
                Ready.Add(p);
                //Console.WriteLine("RunningTOReady");
            }
        }
示例#2
0
        private void JobRunner()
        {
            while (true)
            {
                _enqueueSignal.WaitOne();

                while (JobQueue.Count > 0)
                {
                    Job job = null;
                    lock (_jobQueueLock)
                    {
                        if (JobQueue.Count > 0)
                        {
                            job = JobQueue.Dequeue();
                        }
                    }

                    if (job != null)
                    {
                        job.JobFinished += (o, a) =>
                        {
                            Job j = (Job)o;
                            if (Running.Contains(j))
                            {
                                Running.Remove(j);
                            }

                            _runCompleteSignal.Set();
                        };

                        RunJob(job);
                    }
                }
            }
        }
示例#3
0
 private void ProcessFinish(object sender, System.Timers.ElapsedEventArgs e)
 {
     foreach (Process p in Running)
     {
         if (p.CPU_usage == 100)
         {
             p.Finish();
             Running.Remove(p);
             break;
         }
     }
 }
示例#4
0
 public void BlockProcess(int pid)
 {
     lock (Running)
     {
         foreach (Process p in Running)
         {
             if (p.Pid == pid)
             {
                 p.Blocked();
                 Running.Remove(p);
                 Blocked.Add(p);
             }
         }
     }
 }
        async void doStart(CommandArgs e)
        {
            if (e.Parameters.Count == 0)
            {
                e.Player.SendErrorMessage($"Invalid syntax! Proper syntax: {Commands.Specifier}timeline start <file> [params...]");
                return;
            }

            string filePath = e.Parameters[0];

            if (!e.Player.CanUseTimeline(filePath))
            {
                e.Player.SendErrorMessage("You don't have access to this timeline.");
                return;
            }

            string path = Path.Combine(TShock.SavePath, filePath.EndsWith(".txt") ? filePath : $"{filePath}.txt");

            if (!File.Exists(path))
            {
                e.Player.SendErrorMessage($"'{filePath}' doesn't exist.");
                return;
            }

            string name = Path.GetFileNameWithoutExtension(filePath);

            if (Running.Exists(t => t.Name.Equals(name, StringComparison.OrdinalIgnoreCase)))
            {
                e.Player.SendErrorMessage($"'{name}' is already running.");
                return;
            }

            string data;

            try
            {
                data = File.ReadAllText(path);
            }
            catch (Exception ex)
            {
                e.Player.SendErrorMessage($"Timeline loading failed: {ex.Message}");
                return;
            }

            // Remove the file name
            e.Parameters.RemoveAt(0);
            Timeline timeline = new Timeline(name, data, e.Parameters);

            try
            {
                // Process the timeline and handle all exceptions
                e.Player.SendInfoMessage("Processing timeline...");
                await timeline.Start();

                timeline.Finished += (o, a) => Running.Remove(timeline);
                Running.Add(timeline);

                e.Player.SendSuccessMessage($"{name} started.");
            }
            catch (EmptyTimelineException)
            {
                e.Player.SendErrorMessage($"'{name}' must contain at least one command.");
            }
            catch (MissingParameterException ex)
            {
                e.Player.SendInfoMessage($"'{name}' syntax: {Commands.Specifier}timeline start {name} {ex.Message}");
            }
            catch (CannotRunException ex)
            {
                e.Player.SendErrorMessage(
                    $"Error processing timeline '{name}' at line {ex.Line}: Cannot run {Commands.Specifier}{ex.Command} as the server.");
            }
            catch (TimelineException ex)
            {
                e.Player.SendErrorMessage($"Error processing timeline '{name}' at line {ex.Line}: {ex.Message}");
            }
        }