Vous êtes sur la page 1sur 6

Assignment :

The program should have the option via a menu to either request the user to
input the no. of processes N, The incremental factor for the new and ready list,
and then for each process the arrival time AT, the no. of units of CPU time
required NUT, the incremental factor for the new_list, the incremental factor for
the ready_list, and for each run prompt the user for the unit of time UT(quanta)
allowed for access to the CPU via a data file called data.txt. Or allow the
program to generate a data file using a random number generation function with
the relevant data.
The scheduling of processes within a computer depends upon three main factors:
whether a process is allowed to run to completion for the initial state: there are n processes
in the ready state, there are m process is blocked. Process scheduling algorithm using round
robin scheduling for the specific algorithm used to determine the next job to be scheduled of
execution is not blocked), and each piece of the system over time t release resources for
process of blocking queue.

Program available to a process PCB said that its type is described as follows:
struct PCB_type
{
int pid; // process name
int state; // Process Status
2-- that "execution" state
1-- means "ready" state
0-- that "blocking" state
int cpu_time; // needed for the operation of the CPU time (the time
required to run the chip number)
}
Set two queues will be "ready" state process PCB ready to hang in the
queue; will be "blocked" state hanging in the process of PCB in the queue
blocked. Queue types are described below:
struct QueueNode {
struct PCB_type PCB;
Struct QueueNode * next;
}
And set the whole amount:
struct QueueNode * ready_head = NULL, // ready queue pointer first team
* ready_tail = NULL, // ready queue tail pointer team
* blocked_head = NULL, // blocked queue pointer first team
* blocked_tail = NULL; // blocked queue tail pointer team
3) Design subroutine:

start_state (); // read the hypothetical data, set the initial state of the
system
dispath (); // simulate scheduling
calculate (); // calculate CPU utilization
5. Test Requirements
Test data:
n=2
m=3
t=5
ready_head
blocked_head
dispath () algorithm flow chart:
Firstly we define a series of variables piece for the completion status
FINISH 0 for the running state RUNNING 1 // Ready of the process
READY 2 // io state accessing the I/O state
IO 3 // wait for Input/ output state
WAIT 4 // define the structure
First
1. Define the variables associated
int proc;
int piece; // completion status
#define FINISH 0 // running state
#define RUNNING 1 // Ready
#define READY 2 // io state
#define IO 3 // wait for IO
#define WAIT 4 // define the PCB structure
typedef struct tagPCBS {
// Serial number
long pid; // process name
char pname [10]; // state
int pstate; // total time
int pneedtime; // Start Time
int piostarttime; // takes time

int pioneedtime; // current time


int ptime; // priority
int priority;
} Pcbs, * ppcbs;
This are all the attributes of the process
Second invoke a function to call the process
2, the function declaration
class pcbnode
{
public:
pcbs * pcb;
pcbnode * link;
pcbnode ();
~ pcbnode ();
int run (); // run operation
// end run; int runend ()
void runio (); // IO operations
int ioend (); // io end
int insertnode (pcbnode * p, pcbnode * q); // after the insertion node p q
int deletenode (pcbnode * p, pcbnode * q); // delete nodes p, q for p
precursor
int addnode (pcbnode * p); // node increases
int pcbnode :: isio (); // whether to begin IO
};
Third
Initialize a Polling variable and then call a for a generic scheduling algorithm
// Polling time slice method
/*
* Each time, cpu time plus one, minus one needs time
* Specify the number of time slots for each execution
* Time piece is finished discharged ready queue tail
*/

Events are stored in the eventList structure, ordered by their start time.

// Preemptive priority scheduling


/ ** Remove the top priority of the process from the ready queue to the run
queue and display each process' status one per line
//* Each time you run, running processes priority number minus one, the
process waiting or the next process is assigned priority number plus 1
// * If the ready queue priority number priority process is greater than the
maximum number of priority number running
// * Let the process run out of cpu, discharged to the tail of the ready queue,
the process of the maximum number of priority feed
* Run queue.
*/

Source code:
#include <iostream.h>
#include <string.h>
#include <fstream.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int proc;
int piece; // completion status
#define FINISH 0 // running state
#define RUNNING 1 // Ready
#define READY 2 // io state
#define IO 3 // wait for IO
#define WAIT 4 // define the PCB structure
typedef struct tagPCBS {
// Serial number
long pid; // process name
char pname [10]; // state
int pstate; // total time
int pneedtime; // Start Time
int piostarttime; // takes time
int pioneedtime; // current time
int ptime; // priority
int priority;
} Pcbs, * ppcbs;

// queue node; class pcbnode


class pcbnode
{
public:
pcbs * pcb;
pcbnode * link;
pcbnode ();
~ pcbnode ();
int run (); // run operation
// end run; int runend ()
void runio (); // IO operations
int ioend (); // io end
int insertnode (pcbnode * p, pcbnode * q); // after the insertion node p q
int deletenode (pcbnode * p, pcbnode * q); // delete nodes p, q for p precursor
int addnode (pcbnode * p); // node increases
int pcbnode :: isio (); // whether to begin IO
};
pcbnode :: pcbnode () {
pcb = 0;
link = 0;}
pcbnode :: ~ pcbnode ()
{
if (link)
delete link;
if (pcb)
pcb-> pstate = FINISH;
}
void poll (pcbs * pcb, int pcbsnum)
{
pcbnode running, ready, blocked;
pcbnode * p;
pcbnode * q;
printf ("\nEnter the length of time slice:\n" );
scanf ("% d", piece);
int i;

void priority (pcbs * pcb, int pcbsnum)


{
pcbnode running, ready, blocked;
pcbnode * p, * f, * front;
pcbnode * q;
int i;
/ * The process table in the process added to the ready queue * /
for (i = 0; i <pcbsnum; i ++)
{
p = new pcbnode;
p-> pcb = pcb + i;
ready.addnode (p);
}
void main ()
{
pcbs * pcblist; // Process Table
printf (\nPlease enter the number of Processes:\n" );
scanf ("% d", proc);
int i;
remove ("data.txt ");
pcblist = new pcbs [proc]; // allocate space for the process table
for (i = 0; i <proc; i ++)
newpcb (pcblist + i, i); // generate process
pprint (pcblist, proc);
printf "\n************ round-robin scheduling method ***********" \n);
poll (pcblist, proc); // round robin scheduling method
printf (\n \n \n);
printf ("\n************ non-preemptive scheduling ************\n");
generalpriority (pcblist, proc); // non-preemptive
printf(\n \n \n);
printf "\n************ preemptive priority scheduling method *****\n");
priority (pcblist, proc); // law may preempt
delete pcblist; // release process space
}

Vous aimerez peut-être aussi