I am working on a project and part of the instruction goes like this:
"The whole system allows up to 10 processes currently stay in memory, only one of them is running on the CPU, while the others are in either the Ready Queue or blocked in the Disk queue. Each process has its PCB"

I have been able to create 10 processes and they are running fine. I'm trying to write the code for the Ready and Disk queue and I'm running into a few difficulties. Below is what I came up with. I tried writing two functions for the ready and disk queue but it wasn't working so I decided to write the code in the main function. Any suggestions on how to write the ready and disk queues (functions)?

struct PCB
{
       int PID;
       string process_state;
       int progCount;
       
};
//Selecting process states    
    for (int i = 0; i < 10; i++)
    {
          infile >> processPCB.PID;
          infile >> processPCB.process_state;
          
          if (process_state == newprocess)
          {            
             readyQueue.EnQueue(PID);            
          } 
          
          else if ( process_state == running)
          {
               diskQueue.EnQueue(PID);
          }
          
          else if (process_state == ready)
          {
               diskQueue.EnQueue(PID);
          }
          
          else if (process_state == waiting)
          {
               diskQueue.DeQueue(PID)
               readyQueue.EnQueue(PID);
          }
          
          else
              process_state == terminated;
    }
void blockedDiskQueue(queue &Que, int pid)
{


     
}
          
     
void readyQueue(queue &Que, int pid) 
{ 

     
     
}

I am working on a project and part of the instruction goes like this:
"The whole system allows up to 10 processes currently stay in memory, only one of them is running on the CPU, while the others are in either the Ready Queue or blocked in the Disk queue. Each process has its PCB"

I have been able to create 10 processes and they are running fine. I'm trying to write the code for the Ready and Disk queue and I'm running into a few difficulties. Below is what I came up with. I tried writing two functions for the ready and disk queue but it wasn't working so I decided to write the code in the main function. Any suggestions on how to write the ready and disk queues (functions)?

struct PCB
{
       int PID;
       string process_state;
       int progCount;
       
};
//Selecting process states    
    for (int i = 0; i < 10; i++)
    {
          infile >> processPCB.PID;
          infile >> processPCB.process_state;
          
          if (process_state == newprocess)
          {            
             readyQueue.EnQueue(PID);            
          } 
          
          else if ( process_state == running)
          {
               diskQueue.EnQueue(PID);
          }
          
          else if (process_state == ready)
          {
               diskQueue.EnQueue(PID);
          }
          
          else if (process_state == waiting)
          {
               diskQueue.DeQueue(PID)
               readyQueue.EnQueue(PID);
          }
          
          else
              process_state == terminated;
    }
void blockedDiskQueue(queue &Que, int pid)
{


     
}
          
     
void readyQueue(queue &Que, int pid) 
{ 

     
     
}

So, I've been working on my code, not the "Ready queue" part, and this is what I came up with. However, the function GetProcessTime seems to be doing nothing. I'm not sure what I'm supposed to see on the screen. But for now, write.exe opens 10 times.

#include <iostream>
#include <windows.h>
#include <fstream>
#include "el_t.h"
#include "queue.h"

using namespace std;

ifstream infile;
ofstream outfile;

//void printQueue(queue &Que);
//void readyQueue(queue &Que);
//void blockedDiskQueue(queue &Que);


struct PCB
{
       int     PID;
       string  process_state;
       int     progCount;
       float   readyTime;
       float   cpuTime;
       float   processTime;
       
};
       



int main ()
{
    struct processPCB;
    queue que;
    
    //string running, ready, disk, newprocess, terminated;
    //int count = 0;
 
    
    infile.open("sos.txt");
    outfile.open("sosOut.txt");
    
    //Create process 
 
    STARTUPINFO si;
    PROCESS_INFORMATION pi;
 
    ZeroMemory( &si, sizeof(si) );
    si.cb = sizeof(si);
    ZeroMemory( &pi, sizeof(pi) );
 
 
    while (count < 10)
    {
          // Start the child process.
          if(!CreateProcess( NULL,            // No module name (use command line)
                   "C:\\Windows\\System32\\write.exe", // Command line
                   NULL,                          // Process handle not inheritable
                   NULL,                          // Thread handle not inheritable
                   FALSE,                         // Set handle inheritance to FALSE
                   0,                             // No creation flags
                   NULL,                          // Use parent's environment block
                   NULL,                          // Use parent's starting directory
                   &si,                           // Pointer to STARTUPINFO structure
                   &pi )                          // Pointer to PROCESS_INFORMATION 
                                                  // structure
                   ) 

                   {
                       cout << "CreateProcess failed " << endl;
                       GetLastError();
                   }
                   
                   count++;
                   
                   
    HANDLE hProcess;
    FILETIME kernelTime;
    FILETIME userTime;
    FILETIME createTime;
    FILETIME exitTime;

    GetProcessTimes(hProcess, &createTime, &exitTime, 
                  &kernelTime, &userTime); 
    }
    
    // Wait until child process exits.
    WaitForSingleObject( pi.hProcess, INFINITE );
 
    // Close process and thread handles.
    CloseHandle( pi.hProcess );
    CloseHandle( pi.hThread ); 
   


  /*  //Load processes into the readyQueue
    for (int i = 0; i < 10; i++)
    {
          infile >> processPCB.PID;
          readyQueue.EnQueue(PID);
    }
    
    if (!readyQueue.QueueIsEmpty())
    {
       int pid;
       
       readyQueue.DeQueue(pid);
       cpuRunning(pid);
       diskQueue.EnQueue(pid);
       
       
          
          
          infile >> processPCB.process_state;
          
          if (process_state == newprocess)
          {            
             readyQueue.EnQueue(PID);   
             printQueue(readyQueue);         
          } 
          
          else if ( process_state == running)
          {
               diskQueue.EnQueue(PID);
               printQueue(diskQueue);
          }
          
          else if (process_state == ready)
          {
               diskQueue.EnQueue(PID);
               printQueue(diskQueue);
          }
          
          else if (process_state == waiting)
          {
               diskQueue.DeQueue(PID)
               readyQueue.EnQueue(PID);
               printQueue(readyQueue);
          }
          
          else
              process_state == terminated;
    }*/
    
   
    
    
 //   BOOL WINAPI TerminateProcess(
 // __in  HANDLE hProcess,
 // __in  UINT uExitCode
      //  );
    
    infile.close();
    outfile.close();
 
    system("pause");
    return 0;

}



/*

void printQueue(queue &Que)
{
     queue tempQueue;
     int elem;
     
     while (!Que. QueueIsEmpty())
     {
           Que.DeQueue(elem);
           outfile << elem << " ";
           tempQueue.EnQueue(elem);
     }
     
     while (!tempQueue.QueueIsEmpty())
     {
           tempQueue.DeQueue(elem);
           Que.EnQueue(elem);
     }
}






void blockedDiskQueue(queue &Que, int pid)
{
     

     
}
          
     
void readyQueue(queue &Que, int pid) 
{ 

     
     
}*/
This article has been dead for over six months. Start a new discussion instead.