示例#1
0
        static void pl(process p)
        {
            LinkedListNode <process> i;

            if (list.Count == 0)
            {
                list.AddLast(p);
            }
            else if (p.start_time < list.First.Value.start_time)
            {
                list.AddFirst(p);
            }
            else if (p.start_time >= list.Last.Value.start_time)
            {
                list.AddLast(p);
            }
            else
            {
                i = list.Last;

                while (i.Value.start_time > p.start_time)
                {
                    i = i.Previous;
                }
                list.AddAfter(i, p);
            }
        }
示例#2
0
 //Time calculations and store the final processes' queue in a new list and linked list
 static void arrange(process task, int start, int total, int i)
 {
     task.completionTime  = total - start;
     task.turnArroundTime = task.completionTime - task.arrivalTime;
     task.waitingTime     = task.turnArroundTime - task.burstTime;
     output.Add(task);
 }
示例#3
0
        //*******************************************
        static void RQ(process p)
        {
            if (queue.Count == 0)
            {
                queue.AddFirst(p);
            }
            else if (queue.Count == 1)
            {
                if ((preemptive || queue.First.Value.started == 0) && p.priority < queue.First.Value.priority)
                {
                    queue.AddFirst(p);
                }
                else
                {
                    queue.AddLast(p);
                }
            }
            else if (p.priority > queue.Last.Value.priority)
            {
                queue.AddLast(p);
            }
            else
            {
                LinkedListNode <process> i = preemptive? queue.First : queue.First.Next;

                while (i.Value.priority <= p.priority)
                {
                    i = i.Next;
                }
                queue.AddBefore(i, p);
            }

            /*
             * if(queue.Count == 1 && !preemptive)
             * {
             *  queue.AddLast(p);
             * }
             * else if( p.priority >= queue.Last.Value.priority)
             * {
             *  queue.AddLast(p);
             * }
             * else if(p.priority < queue.First.Value.priority)
             * {
             *  if (preemptive)
             *      queue.AddFirst(p);
             *
             *
             * }
             * else if (p.priority > 5/2)
             * {
             *  LinkedListNode<process> i = queue.First;
             *  if (!preemptive)
             *  {
             *      i = i.Next;
             *  }
             *
             *
             *  while(i.Value.priority >= p.priority)
             *  {
             *      i = i.Next;
             *  }
             *  queue.AddBefore(i, p);
             *
             * }
             * else
             * {
             *  LinkedListNode<process> i = queue.Last;
             *  while(i.Value.priority < p.priority)
             *  {
             *      i = i.Previous;
             *  }
             *  queue.AddAfter(i, p);
             * }
             */
        }
示例#4
0
        unsafe static void Main(string[] args)
        {
            preemptive = false;
            string  q;
            process p = new process();
            float   P_num; // number of process entered by the user
            int     i;     // flag for the loops
            int     d;     // detect the current timing of the process
            float   waiting = 0;

            Console.WriteLine("******** Settings for the system **********\n");
            Console.WriteLine("Do you want it preemptive? (y/n)");
            q = Console.ReadLine();
            if (q[0] == 'y')
            {
                preemptive = true;
            }


            Console.Write("Enter number of process : ");
            P_num = Convert.ToInt32(Console.ReadLine());
            for (i = 0; i < P_num; i++)
            {
                p.num = i + 1;
                Console.Write("\nEnter start time of process " + (i + 1) + ": ");
                p.start_time = Convert.ToInt32(Console.ReadLine());

                Console.Write("Enter duration of process " + (i + 1) + ": ");
                p.duration = Convert.ToInt32(Console.ReadLine());

                Console.Write("Enter priority of process " + (i + 1) + ": ");
                p.priority = Convert.ToInt32(Console.ReadLine());

                p.started = 0;
                pl(p);
            }
            Console.Write("\nSequence : ");

            LinkedListNode <process> k = list.First;

            d = k.Value.start_time;

            RQ(k.Value);
            k = k.Next;
            list.RemoveFirst();

            while (queue.Count != 0 || list.Count != 0)
            {
                if (k != null && k.Value.start_time == d)
                {
                    RQ(k.Value);
                    k = k.Next;
                    list.RemoveFirst();
                }
                else if (queue.Count == 0)
                {
                    d++;
                }
                else
                {
                    Console.Write(queue.First.Value.num + " ");
                    p = queue.First.Value;
                    queue.RemoveFirst();
                    p.started++;
                    d++;
                    if (p.started == p.duration)
                    {
                        waiting += (d - p.duration - p.start_time) / P_num;
                    }
                    else
                    {
                        queue.AddFirst(p);
                    }
                }
            }

            Console.Write("\nAverage waiting time = " + waiting + "\n");
        }
示例#5
0
        static void Round_R()
        {
            process p = new process();
            int     d;          // detect the current timing of the process
            float   waiting = 0;

            var k = processes[0];

            d = k.arrivalTime;
            queue.AddFirst(k);

            processes.RemoveAt(0);
            if (processes.Count != 0)
            {
                k = processes[0];
            }
            else
            {
                k.end = 1;
            }
            float turnAroundTime       = 0;
            var   temp                 = queue.First;
            bool  detectProcessRemoval = false;

            bool smallerProcess = false;

            while (queue.Count != 0 || processes.Count != 0)
            {
                if ((k.end != 1 && k.arrivalTime <= d) && d != 0)
                {
                    if (detectProcessRemoval)
                    {
                        queue.AddLast(k);
                        processes.RemoveAt(0);
                        if (processes.Count == 0)
                        {
                            k.end = 1;
                        }
                        else
                        {
                            k = processes[0];
                        }
                        detectProcessRemoval = false;
                        while (k.end != 1 && k.arrivalTime <= d)
                        {
                            queue.AddLast(k);
                            if (processes.Count == 0)
                            {
                                k.end = 1;
                            }
                            else
                            {
                                k = processes[0];
                            }
                            processes.RemoveAt(0);
                        }
                    }
                    else
                    {
                        temp = queue.Last;
                        queue.AddBefore(temp, k);
                        if (processes.Count == 0)
                        {
                            k.end = 1;
                        }
                        else
                        {
                            k = processes[0];
                        }
                        list.RemoveFirst();
                    }
                }
                else
                {
                    if (output[output.Count - 1].pID == queue.First.Value.pID)
                    {
                        process m = output[output.Count - 1];
                        m.on_time++;
                        output.RemoveAt(output.Count - 1);
                        output.Add(m);
                    }
                    else
                    {
                        output.Add(queue.First.Value);
                    }
                    smallerProcess = false;
                    p = queue.First.Value;

                    if (p.burstTime > quantumTime)
                    {
                        p.burstTime -= quantumTime;
                        queue.RemoveFirst();
                        queue.AddLast(p);
                    }
                    else
                    {
                        smallerProcess = true;
                        d             += p.burstTime;
                        p.burstTime    = 0;
                        turnAroundTime = (d - p.arrivalTime);
                        waiting        = waiting + (turnAroundTime - burstTime[queue.First.Value.pID - 1]) / (P_pID);
                        queue.RemoveFirst();
                        detectProcessRemoval = true;
                    }
                    if (!smallerProcess)
                    {
                        d += quantumTime;
                    }
                }
            }
        }
示例#6
0
 static void RQ(process p)
 {
     if (process_type == "SJF")
     {
         if (queue.Count == 0)
         {
             queue.AddFirst(p);
         }
         else if (queue.Count == 1)
         {
             if ((preemptive || queue.First.Value.started == 0) && p.burstTime < queue.First.Value.burstTime)
             {
                 queue.AddFirst(p);
             }
             else
             {
                 queue.AddLast(p);
             }
         }
         else if (p.burstTime > queue.Last.Value.burstTime)
         {
             queue.AddLast(p);
         }
         else
         {
             LinkedListNode <process> i = preemptive ? queue.First : queue.First.Next;
             while (i.Value.burstTime <= p.burstTime)
             {
                 i = i.Next;
             }
             queue.AddBefore(i, p);
         }
     }
     else if (process_type == "priority")
     {
         if (queue.Count == 0)
         {
             queue.AddFirst(p);
         }
         else if (queue.Count == 1)
         {
             if ((preemptive || queue.First.Value.started == 0) && p.priority < queue.First.Value.priority)
             {
                 queue.AddFirst(p);
             }
             else
             {
                 queue.AddLast(p);
             }
         }
         else if (p.priority > queue.Last.Value.priority)
         {
             queue.AddLast(p);
         }
         else
         {
             LinkedListNode <process> i = preemptive ? queue.First : queue.First.Next;
             while (i.Value.priority <= p.priority)
             {
                 i = i.Next;
             }
             queue.AddBefore(i, p);
         }
     }
 }
示例#7
0
        static void priority_sjf()
        {
            process p = new process();
            int     d;          // detect the current timing of the process
            float   waiting = 0;


            // var k = list.First;
            var k = processes[0];

            d = k.arrivalTime;

            RQ(k);

            processes.RemoveAt(0);
            if (processes.Count != 0)
            {
                k = processes[0];
            }
            else
            {
                k.end = 1;
            }
            float turnAroundTime = 0;

            while (queue.Count != 0 || processes.Count != 0)
            {
                if (k.end != 1 && k.arrivalTime == d)
                {
                    RQ(k);
                    processes.RemoveAt(0);
                    if (processes.Count == 0)
                    {
                        k.end = 1;
                    }
                    else
                    {
                        k = processes[0];
                    }
                }

                else
                {
                    //Console.Write(queue.First.Value.pID + " ");
                    p = queue.First.Value;

                    queue.RemoveFirst();
                    p.started++;
                    d++;
                    if (p.started == p.burstTime)
                    {
                        turnAroundTime = (d - p.arrivalTime);
                        waiting        = waiting + (turnAroundTime - p.burstTime) / P_pID;
                    }
                    else
                    {
                        queue.AddFirst(p);
                    }

                    if (output[output.Count - 1].pID == p.pID)
                    {
                        process m = output[output.Count - 1];
                        m.on_time++;
                        output.RemoveAt(output.Count - 1);
                        output.Add(m);
                    }
                    else
                    {
                        output.Add(p);
                    }
                }
            }
        }