public void SJF()
 {
     //Sort readyQueue in priority order
     int n = LongTermScheduler.readyQueue.Count;
     bool doMore = true;
     while (doMore)
     {
         n--;
         doMore = false;
         for (int i = 0; i < n ; i++)
         {
             Job j1 = LongTermScheduler.readyQueue[i];
             Job j2 = LongTermScheduler.readyQueue[i + 1];
             if (j1.jobPriority < j2.jobPriority)
             {
                 job = j1;
                 LongTermScheduler.readyQueue[i] = LongTermScheduler.readyQueue[i + 1];
                 LongTermScheduler.readyQueue[i + 1] = job;
                 doMore = true;
             }
         }
     }
 }
        public void Start()
        {
            if (HasLoadedAllJobs())
            {
                textOutPut("ALL JOBS HAVE COMPLETED.");
                RamPercent(1);
                OSDriver.DONE = true;
                return;
            }
            else
            {
                loc = 0;
                Memleft = 1024;
            }
            if (CURRJOB >= OSDriver.PCB.GetJobCount())
            {
                OSDriver.DONE = true;
                return;
            }
            job = OSDriver.PCB.GetJob(CURRJOB);

            jobStart = job.DiskAddress;
            jobSize = job.jobSize;
            jobIBSize = job.InBufferSize;
            jobOBSize = job.OutBufferSize;
            jobTBSize = job.TmpBufferSize;
            dataSize = job.DataSize;

            textOutPut("Start: " + jobStart);
            textOutPut("Size: " + jobSize);
            textOutPut("IP Buffer Size: " + jobIBSize);
            textOutPut("OP Buffer Size: " + jobOBSize);
            textOutPut("TMP Buffer Size: " + jobTBSize);

            textOutPut("\nIs there enough memory left for the next job? " + (Memleft >= ((jobSize * 4) + (jobIBSize * 4))));
            textOutPut("Have we reached the end of the job list? " + (CURRJOB < OSDriver.PCB.GetJobCount() + 1));

            while (Memleft >= (jobSize * 4) && (CURRJOB < OSDriver.PCB.GetJobCount()))
            {

                job.MemStart = loc;
                int v = jobStart + jobSize;

                for (int p = jobStart; p < v; p++)
                {

                    String binaryBits = OSDriver.tools.getBinaryData(p);
                    textOutPut("Binary bits: " + binaryBits);

                    string tmps = "";
                    tmps = binaryBits.Substring(0, 8);
                    int binaryBits1 = NumericConvert.BinaryToInt(tmps);
                    textOutPut(binaryBits1);
                    textOutPut(String.Format("Decimal: {0}\t added at location: {1}", binaryBits1, loc));
                    OSDriver.MemManager.WriteRamData(loc++, binaryBits1);
                    tmps = binaryBits.Substring(8, 8);
                    int binaryBits2 = NumericConvert.BinaryToInt(tmps);
                    textOutPut(binaryBits2);
                    textOutPut(String.Format("Decimal: {0}\t added at location: {1}", binaryBits2, loc));
                    OSDriver.MemManager.WriteRamData(loc++, binaryBits2);
                    tmps = binaryBits.Substring(16, 8);
                    int binaryBits3 = NumericConvert.BinaryToInt(tmps);
                    textOutPut(binaryBits3);
                    textOutPut(String.Format("Decimal: {0}\t added at location: {1}", binaryBits3, loc));
                    OSDriver.MemManager.WriteRamData(loc++, binaryBits3);
                    tmps = binaryBits.Substring(24, 8);
                    int binaryBits4 = NumericConvert.BinaryToInt(tmps);
                    textOutPut(binaryBits4);
                    textOutPut(String.Format("Decimal: {0}\t added at location: {1}", binaryBits4, loc));
                    OSDriver.MemManager.WriteRamData(loc++, binaryBits4);

                    Memleft -= 4;
                }

                textOutPut(String.Format("Data Size: {0} and location is {1}", dataSize, loc));
                int z = 0;
                int[] tmp = new int[dataSize * 4];

                String binaryDataBits;
                //Get input buffer from datafile and save it in PCB
                while (z < job.DataSize * 4)
                {
                    textOutPut("GETTING JOB DATA...");
                    binaryDataBits = ToBinaryString(v++);
                    tmp[z++] = NumericConvert.BinaryToInt(binaryDataBits.Substring(24, 8));
                    tmp[z++] = NumericConvert.BinaryToInt(binaryDataBits.Substring(16, 8));
                    tmp[z++] = NumericConvert.BinaryToInt(binaryDataBits.Substring(8, 8));
                    tmp[z++] = NumericConvert.BinaryToInt(binaryDataBits.Substring(0, 8));
                }
                job.IPBuffers = tmp;
                job.MemEnd = loc;
                job.SetStatus(ready);

                //Add the job to the ready queue and record the time.
                readyQueue.Add(job);
                job.EnQueueTime = Environment.TickCount;

                textOutPut(String.Format("Added job: {0} at address: {1}-{2}\n", CURRJOB, job.MemStart, job.MemEnd));
                if (CURRJOB >= OSDriver.PCB.GetJobCount())
                {
                    OSDriver.DONE = true;
                    return;
                }
                CURRJOB++;
                textOutPut("Is the current job < total jobs " + (CURRJOB < OSDriver.PCB.GetJobCount()));
                textOutPut(String.Format("Current job: {0}\tTotal jobs: {1}", CURRJOB, OSDriver.PCB.GetJobCount()));

                if (CURRJOB < OSDriver.PCB.GetJobCount())
                {
                    textOutPut("CURRENT JOB: " + CURRJOB);
                    job = OSDriver.PCB.GetJob(CURRJOB);
                    jobStart = job.DiskAddress;
                    jobSize = job.jobSize;
                    dataSize = job.DataSize;
                    jobIBSize = job.InBufferSize;
                }
                else
                {
                    RamPercent(1);
                    OSDriver.DONE = true;
                }
            }
            RamPercent(0);
        }
 public void createJob(int i, int s, int p, int a)
 {
     pcb_e = new Job(i, s, p, a);
 }
Пример #4
0
 internal void Load(Form1 form1, Job jMeta)
 {
     this.form = form1;
     Load(jMeta);
 }
Пример #5
0
        public void Load(Job job)
        {
            j = job;
            ioCount = 0;
            output.WriteLine("\n|||||||||||||||||");
            output.WriteLine("\nJob #" + j.jobID);
            textOutPut(String.Format("\nJob #{0} EXECUTING", j.jobID));

            //set the pc counter & buffer sizes
            pc = j.MemStart;
            oBufferSize = j.OutBufferSize;//size in # of words
            iBufferSize = j.inputBufferSize;
            tBufferSize = j.TmpBufferSize;
            cpu_buffer = j.IPBuffers;
            jobSize = j.jobSize;
            textOutPut(String.Format("Program Counter starting at: {0}\n", pc));
            //run the duration of the job
            while (pc < j.MemEnd)
            {
                String instr = FetchInstruction(pc);
                execute(Decode(instr), j.jobID);
                if (!jumped)
                    pc += 4;
                else
                    jumped = false;

                output.WriteLine("\n\nPROGRAM COUNTER=" + pc);
                textOutPut("PROGRAM COUNTER=" + pc);
            }
        }