Esempio n. 1
0
        public List <PCB> manageQueue(List <PCB> cola)
        {
            try
            {
                //Pending to add kernel processes to count
                if (runningProcesses.Count < 4)
                {
                    PCB newKernelPCB = cola[0];
                    for (int i = 0; i < 4; i++)
                    {
                        if (screens[i])
                        {
                            newKernelPCB.quadrant = i + 1;
                            screens[i]            = false;
                            break;
                        }
                    }
                    runningProcesses.Add(newKernelPCB);
                    //runningProcesses.Add(cola[0]);
                    cola.RemoveAt(0);
                    //cola.TrimExcess();
                }
            }
            catch (ArgumentOutOfRangeException)
            {
            }

            return(cola);
        }
Esempio n. 2
0
        public static void chooseFunc(PCB pcb)
        {
            switch (pcb.function_number)
            {
            case 0:
                pcb.funcion = idle;
                //pcb.quadrant = 4;
                break;

            case 1:
                pcb.funcion = f1;
                //pcb.quadrant = 1;
                break;

            case 2:
                pcb.funcion = f2;
                //pcb.quadrant = 2;
                break;

            case 3:
                pcb.funcion = f3;
                //pcb.quadrant = 3;
                break;
            }
        }
Esempio n. 3
0
        public PLP()
        {
            PCB idle = new PCB(0, 0);

            idle.quadrant = 1;
            runningProcesses.Add(idle);
        }
        public PCB getRunningPCB()
        {
            Console.WriteLine(plp.runningProcesses.Count());
            PCB next = plp.getNextPCB();


            return(next);
        }
Esempio n. 5
0
        public PCB getNextPCB()
        {
            if (currentIndex == runningProcesses.Count)
            {
                currentIndex = 0;
            }
            PCB nextPCB = runningProcesses[currentIndex];

            currentIndex++;

            return(nextPCB);
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            //drawScreen();
            PCB testingPCB = new PCB(10, 1);

            testingPCB.funcion  = f1;
            testingPCB.quadrant = 1;
            //currentPCB = testingPCB;


            PCB otroPCB = new PCB(5, 1);

            otroPCB.quadrant = 2;
            otroPCB.funcion  = idle;

            int          i     = 0;
            ProcessAdmin admin = new ProcessAdmin();



            //admin.listener();
            //currentPCB = admin.getCurrentRunningProcess()
            currentPCB = admin.getRunningPCB();
            currentPCB.activate();
            while (true)
            {
                try
                {
                    Thread input = new Thread(() => admin.getInput());
                    //Console.WriteLine(currentPCB.idproc);
                    chooseFunc(currentPCB);


                    currentPCB.funcion();
                    sm.drawScreen();
                    input.Start();



                    //Task screen = new Task(() => sm.drawScreen());
                    //screen.Start();

                    //thread.IsBackground = true;
                    //sm.drawScreen();
                    //Thread t2 = new Thread(() => admin.getInput());
                    //t2.Start();
                    //admin.getInput();
                    currentPCB = admin.getRunningPCB();
                }
                catch (System.ArgumentException)
                {
                }
                System.Threading.Thread.Sleep(3 * 1000);

                /*
                 * int height = Console.WindowHeight;
                 * int width = Console.WindowWidth;
                 *
                 * //Console.WriteLine("Height: " + height + "\nWidth: " + width);
                 *
                 *
                 *
                 * i++;
                 *
                 *
                 * //Console.WriteLine("AreaHeight: " + areaHeights + "\nAreaWidth: " + areaWidths);
                 *
                 * // jumb between areas
                 * if(i % 4 == 0)
                 * {
                 *  idle(4);
                 * }
                 * else if(i % 3 == 0)
                 * {
                 *  sm.AddLineToBuffer(ref sm.area3, i.ToString());
                 * }
                 * else if(i % 2 == 0)
                 * {
                 *  sm.AddLineToBuffer(ref sm.area2, i.ToString());
                 * }
                 * else
                 * {
                 *  sm.AddLineToBuffer(ref sm.area1, i.ToString());
                 * }
                 */

                //admin.getInput(); // getting options from user afterwards: verify received input.
            }
        }
        public void solve(string[] cmds)
        {
            /*
             * foreach (string cmd in cmds){
             * Console.WriteLine(cmd);
             * } */

            switch (cmds[0])
            {
            case "-h":
                Console.Clear();
                // Code block to execute when command is -h (help)
                Console.WriteLine("Commands: \nAdd (int)<<function_type>>  (int)<<quantum number>> \n Function Types: 1. F1 | 2. F2 | 3. F3 | 4. F4 \n");
                Console.WriteLine("Chn (int)<<processId>> (int)<<quantum number>> \n");
                Console.WriteLine("Lstprc \n");
                Console.WriteLine("Kill (int)<<processId>> \n");
                Console.WriteLine("Press ANY key to continue...");
                Console.ReadKey();
                // recibir input de nuevo.
                //getInput();
                break;

            case "Add":
                // code block to execute when command is Add
                //Console.WriteLine(cmd);
                //Console.WriteLine(cmd.Length.ToString());
                if (cmds.Length == 3)
                {
                    if ((Convert.ToInt32(cmds[1]) > 0) && (Convert.ToInt32(cmds[1]) < 4))
                    {
                        Console.WriteLine("Command Add: \n Function Type: {0} \n Quantum Number: {1}", cmds[1], cmds[2]);
                        PCB current_pcb = new PCB(Convert.ToInt32(cmds[2]), Convert.ToInt32(cmds[1]));
                        pcp.PCB_encola(current_pcb);
                        pcp.PCB_cola = plp.manageQueue(pcp.PCB_cola);
                        f.waitForKeyPress();
                    }
                    else
                    {
                        Console.WriteLine("Invalid function number");
                        f.waitForKeyPress();
                    }
                }
                else
                {
                    Console.WriteLine("Incomplete command.");
                    f.waitForKeyPress();
                }

                break;

            case "Chn":
                // code block to execute when comand is Chn (change)
                if (cmds.Length == 3)
                {
                    bool encontro;
                    int  idp = Convert.ToInt32(cmds[1]);
                    int  qtm = Convert.ToInt32(cmds[2]);

                    Console.WriteLine("Command Chn: \n ProcessId: {0} \n Quantum Number: {1}", cmds[1], cmds[2]);
                    encontro = pcp.PCB_chn(Convert.ToInt32(cmds[1]), Convert.ToInt32(cmds[2]));

                    if (encontro)
                    {
                        Console.WriteLine("Nuevo Quantum {0} asignado al Proceso ID#{1}", qtm, idp);
                    }
                    else
                    {
                        Console.WriteLine("No se pudo cambiar el quantum {1} del proceso #{0} | Ya que no fue encontrado. \n", idp, qtm);
                    }
                    f.waitForKeyPress();
                }
                else
                {
                    Console.WriteLine("Incomplete command.");
                    f.waitForKeyPress();
                }

                break;

            case "Lstprc":
                // code block to execute when comand is Lstprc (list processes)
                Console.WriteLine("Command Listprc");
                plp.PLP_list();
                pcp.PCB_list();

                f.waitForKeyPress();
                break;

            case "Kill":
                // code block to execute when command is Kill
                if (cmds.Length == 2)
                {
                    bool encontro;

                    encontro = plp.PLP_kill(Convert.ToInt32(cmds[1]));
                    if (!encontro)
                    {
                        pcp.PCB_kill(Convert.ToInt32(cmds[1]));
                    }

                    // Console.WriteLine("ProcessId {0} kiled \n", cmds[1]);


                    if (encontro)
                    {
                        Console.WriteLine("Proceso ID#{0} killed", Convert.ToInt32(cmds[1]));
                        pcp.PCB_cola = plp.manageQueue(pcp.PCB_cola);
                    }
                    else
                    {
                        Console.WriteLine("No se pudo kill el proceso proceso #{0} | Ya que no fue encontrado. \n", Convert.ToInt32(cmds[1]));
                    }


                    f.waitForKeyPress();
                }
                else
                {
                    Console.WriteLine("Incomplete command.");
                    f.waitForKeyPress();
                }

                break;

            default:
                // code block
                Console.WriteLine("Incorrect command");
                getInput();
                break;
            }
        }
Esempio n. 8
0
 public void addToKernel(PCB PCBtoadd)
 {
     runningProcesses.Add(PCBtoadd);
 }
Esempio n. 9
0
 public void PCB_encola(PCB newPCB)
 {
     PCB_cola.Add(newPCB);
     Console.WriteLine("Se insertó a cola Idproc:  {0}\n", newPCB.idproc);
 }