Operating system course design is completed

zhaozj2021-02-16  49

I finally got a good course design, but I didn't do it I did.

Two: Process Scheduling Simulation

Design requirements:

Write a program that can create several virtual processes and scheduling a number of virtual processes, and the scheduling policy is a time slice.

Description of the virtual program:

Format of virtual instructions: Operation command operation time

Among them, the operational commands have the following:

l C: Indicates the calculation on the CPU

l i: indicates input

l o: Indicates the output

l W: means waiting

l h: indicates the end of the process

How long does the operation time represent the action command to do?

Suppose the number of I / O devices is not limited

I, O, W The three instructions do not occupy the CPU. If these three instructions should be put into the corresponding waiting queue (INPUT wait queue, Output waiting queue, Wait waiting queue)

Example has a virtual program P1.prc as follows:

C 30

O 12

C 9

i 14

H 0

The meaning of the virtual program is: first calculate 30 seconds on the CPU, then output 12 seconds on the output device, calculate 9 seconds, enter 14 seconds on the input device, and the program ends.

experimental method:

Firstly write three virtual programs with a text editor, you can name P1.PRC P2.PRC P3.PRC, respectively. Then edit the process scheduler, create these three virtual programs into processes, and perform and schedulize according to the instructions of each virtual process. With a text file, only one integer can be placed, indicating a time factor, and is used to adjust the execution speed of the design program OS.exe.

Run results requirements:

You are required to display a row prompt information when each thread is created, occupying a processor, start output, start input, and end operation, respectively, to determine all processing compliance with the corresponding process schedule rules.

Claim:

Design analysis, solution

2. Creating the process To create a process control block (you can refer to the design of the process control block of UINX, requires the necessary information for progress)

3. To have a run queue, ready queue, input waiting queue, Output waiting queue, wait waiting queue

4. The context conversion process when there is a process switching

5. To dynamically display the current status and instruction execution of each process, dynamically display the current state of each queue

6. Draw the basic structural block diagram of the program and flow chart

7. There must be a detailed design and analysis instructions for each part of the program, indicating the principles used by the design implementation, the data structure adopted

8. Detailed description of the various operation functions of the process (such as creating processes, destruction process, etc.)

9. Source code format specification, not less than one-third

10. There must be results in the result of the result.

11. The problems encountered in the design, the experience of designing

12. Reference

13. Development tools are not limited

System flow chart:

1.3 homework

2. Implement process schedule according to time slice rotation

3. Five public queues

Execute queue

Time film

Ready to wait for queue

CPU

C

Timekeeping

Waiting for the end

C

Enter the waiting queue

I

Hide

end

Output waiting queue

O

Blocking waiting queue

W

Source program

#define null 0

#include

#include

#include

#include

/ / Define a PCB structure

File * groupfile [10];

Typedef struct index {

Char name; / / instruction int Time; // instruction execution time

INDEX;

Struct pcb {

Char filename [10]; // process name

INT ID; // Job number

INT EXTOINDEX; // Currently in executing instructions

Char status; // Current state

INT WTIME; // Waiting time

}

Struct PCB JobPCB [100]; // PCB table

Typedef struct job {

INDEX IDX [100]; // instruction set

INT pcbnum; // PCB number

} JOB;

Job jobtab [100]; // work table

Char jobp [3] [50]; // homework

//queue

Struct Qnode

{

INT pcbnum [100]; // PCB number

INT Head, TAIL;

}

Struct Qnode Queue [5]; // 5 Queen 0e 1R 2i 3o 4W

Void initQueue (struct Qnode * L);

//delay

Void delay () {

Long Begin, End;

Time (& recomgin);

Do {

Time (& End);

} while (end-begin <= 1);

}

// Character conversion to a value

INT Change (char * m) {

INT I, J = 0;

INT LEN = Strlen (M);

For (i = 0; i

J = j * 10 m [i] - '0';

Return J;

}

// Apply for a PCB

Int allocpcb () {

INT I;

For (i = 0; i <3; i )

IF (JOBPCB [I] .ID == - 1) Break;

IF (i <3)

Return I;

Return -1;

}

// Apply for Job

Int allocjob () {

INT I;

For (i = 0; i <3; i )

IF (JobTab [i] .pcbnum == -1) Break;

IF (i <3)

Return I;

Return -1;

}

// Display instructions

Void DisplayIndex () {

INT I, J;

For (i = 0; i <3; i ) {

Printf ("JOB% D / N", I 1);

For (j = 0; j <10; j )

Printf ("% D% C% D / N", J 1, JobTab [i] .idx [j] .name, jobtab [i] .idx [j] .time);

}

}

// Create a process program

INT CREATPCBLINE () {

Char line [10];

INT I, LL, JNUM, PNUM, LN = 0, BPOS, POS = 0;

CHAR BUFF [50];

Char Name [20];

CHAR CH;

For (i = 0; i <3; i ) {

ln = 0;

JNUM = allocjob ();

IF (jnum == -1) Return 0;

PNUM = allocpcb ();

IF (pnum == -1) Return 0;

JobTab [jnum] .pcbnum = pnum;

STRCPY (JOBPCB [PNUM] .fileName, ""); JobPCB [PNUM] .status = 'r';

JobPCB [PNUM] .exetoIndex = 0;

JobPCB [PNUM] .id = jnum;

Jobpcb [pnum] .wtime = 0;

INT ln = strlen (jobp [i]);

POS = 0;

While (POS

While (jobp [i] [pOS] == ') POS ;

Jobtab [jnum] .idx [ln] .name = jobp [i] [pOS ]; ///

While (jobp [i] [pOS] == ') POS ;

BPOS = 0;

While (jobp [i] [pOS]! = '')

Buff [BPOS ] = JOBP [i] [POS ];

BUFF [BPOS] = '/ 0';

JobTab [jnum] .idx [ln] .time = change (buff); /

IF (POS

}

}

}

DisplayIndex ();

}

/ * Initialization queue

Void initQueue (struct Qnode * L) {

L-> Head = 0;

L-> TAIL = 0;

}

// Plug into the queue /

Void InsertQueue (struct Qnode * L, int PCBNUM) {

L-> PCBNUM [L-> Tail ] = PCBNUM;

}

/ / Does the queue are empty?

INT EmptyQueue (struct Qnode L) {

IF (L.HEAD == L. Tail) Return 1;

Return 0;

}

// Delete the queue

Void Outqueue (struct Qnode * L, INT * PCBNUM)

{

IF (L-> Head> = L-> TAIL) * pcbnum = -1;

Else

* PCBNUM = L-> PCBNUM [L-> Head ];

}

// Display job

Void Display () {

INT I, J;

For (i = 0; i <5; i ) {

Printf ("Queue% D", I);

For (j = queue [i] .head; j

Printf ("PCB Number% D / N / N", Queue [i] .pcbnum [j]);

}

}

// Homework into the queue

Void JobenqueUeinit (int * total) {

INT I, NUM, INDEX = 0;

CHAR CMD;

For (i = 0; i <3; i ) {

IF (JOBPCB [I] .ID> = 0) {

CMD = jobtab [JobPCB [i] .id] .idx [index] .name

Switch (cmd) {

Case 'c': INSERTQUEUE (& Queue [1], I); JobPCB [i] .status = 'r'; Break;

Case 'I': INSERTQUEUE (& Queue "; JobPCB [I] .status = 'i'; Break; Case 'o': INSERTQUEUE (& Queue [3], i); JobPCB [i]. STATUS = 'o'; Break;

Case 'W': INSERTQUEUE (& Queue [4], I); JobPCB [I] .status = 'W'; Break;

Case 'h': jobpcb [i] .status = 'h'; Num = jobpcb [i] .id; jobtab [Num] .pcbnum = -1; jobpcb [i] .ID = -1;

}

IF (cmd == 'h') {jobpcb [i] .wtime = 0; Total ---;

Jobpcb [i] .wtime = jobtab [jobpcb [i] .id] .idx [index] .time;

(* Total) ;

}

}

}

Void save () {

File * fp;

INT I;

FP = fopen ("pcbtable.txt", "a");

FPRINTF (FP, "file name job number is performed to the status of the command time / N");

For (i = 0; i <3; i )

FPRINTF (FP, "/ T% S / T% D / T% D / T% C / T% D / N",

Jobpcb [i] .filename, Jobpcb [i] .id, jobpcb [i] .exetoIndex,

Jobpcb [i] .status, jobpcb [i] .wtime);

Fclose (fp);

}

// Homework into the queue

Void Jobenqueue (int PCBNUM, INT INDEX, INT * TOTAL) {

Int Num;

CHAR CMD;

IF (JOBPCB [PCBNUM] .ID> = 0) {

CMD = JobTab [JobPCB [PCBNUM] .id] .idx [index] .name;

Switch (cmd) {

Case 'c': INSERTQUEUE (& queue "; JobPCB [PCBNUM] .status = 'r'; Break;

Case 'I': InsertQueue (& Queue [2], PCBNUM); JobPCB [PCBNUM] .status = 'I'; Break;

Case 'o': INSERTQUEUE (& Queue [3], PCBNUM); JobPCB [PCBNUM] .status = 'o'; Break;

Case 'W': INSERTQUEUE (& queue [4], PCBNUM); JobPCB [PCBNUM] .status = 'w'; Break;

Case 'h': jobpcb [pcbnum] .status = 'h'; Num = Jobpcb [PCBNUM] .id; jobtab [NUM] .pcbnum = -1; JobPCB [PCBNUM] .ID = -1;

}

IF (cmd == 'h') {

JobPCB [PCBNUM] .wtime = 0;

Printf ("/ N / T / T job% D complete / N", PCBNUM 1, JOBPCB [PCBNUM] .status; (* TOTAL) -;

}

Else JobPCB [PCBNUM] .wtime = jobtab [jobpcb [pcbnum] .id] .idx [index] .time;

Printf ("/ N / T / T job% D / N", PCBNUM 1);

Printf ("/ t / t / t / t state:% C / N", JobPCB [PCBNUM] .status);

Printf ("/ t / t required time% D second / N", JobPCB [PCBNUM] .wtime);

}

}

/ / Get the first element of the queue

INT GetHead (Struct Qnode L) {

Return L.PCBNUM [L.HEAD];

}

//carried out

Void Run () {

INT I, FLAG = 0, TIME = 10, PCBNUM, INDEX = 0, Exenum, Num, quenum

CHAR CMD;

INT J, M, N;

INT TOTAL = 0;

Jobenqueueinit (& TOTAL);

Save ();

While (Total! = 0) {

IF (! EmptyQueue (Queue [1])) {

Outqueue (& queue "; & pcbnum);

INSERTQUEUE (& Queue [0], PCBNUM);

Else Pcbnum = GetHead (Queue [0]);

DELAY ();

JobPCB [PCBNUM] .status = 'e';

Printf ("/ N / T / T job% D / N", PCBNUM 1);

Printf ("/ T / T / T state:% C / T execute% D second / N", JobPCB [PCBNUM] .status, Time);

For (i = 0; i <3; i ) {

IF (JOBPCB [I] .ID> = 0) {

// All jobs are waiting for the external waiting time interval time slice in the ready team

IF (JobPCB [i] .status! = 'r' && jobpcb [i] .status! = 'h') jobpcb [i] .wtime = jobpcb [i] .wtime-time;

IF (jobpcb [i] .wtime <= 0) {// Find all queues location

For (j = 0; j <5; j ) {

For (m = queue [j] .head; m

IF (Queue [J] .pcbnum [M] == i) {FLAG = 1; Break;}

}

IF (Flag == 1) Break;

}

IF (FLAG == 1) {// Remove the instruction

For (n = m; n

Queue [j] .tail--;

Jobpcb [i] .exetoIndex ;

INDEX = JOBPCB [I] .ExetoIndex;

Jobenqueue (i, index, & total);

}

}

}

}

IF (! EmptyQueue (Queue [1])) {

Outqueue (& Queue [0], & PCBNUM); if (JobPCB [PCBNUM] .wtime> 0) {

INSERTQUEUE (& Queue [1], PCBNUM);

JobPCB [PCBNUM] .status = 'r';

}

}

Printf ("/ N / N / T / T also / t% D job is not completed / N", TOTAL);

Save ();

}

}

//initialization

VoidiniTfile () {

INT I;

STRCPY (JOBP [0], "C 20 I 20 O 15 h 0");

STRCPY (JOBP [1], "I 10 C 20 C 10 H 0");

STRCPY (JOBP [2], "C 30 I 20 C 5 H 0");

For (i = 0; i <100; i ) {

Jobpcb [i] .exetoIndex = 0;

STRCPY (JOBPCB [i] .filename, "");

Jobpcb [i] .id = -1;

Jobpcb [i] .status = 'r';

Jobpcb [i] .wtime = 0;

}

For (i = 0; i <100; i )

JobTab [i] .pcbnum = -1;

For (i = 0; i <5; i )

InitQueue (& queue [i]);

//Groupfile[0]=fopen ("1.txt", "r ");

//Groupfile[1]=fopen ("2.txt", "r ");

//Groupfile[2]=fopen ("3.txt", "r ");

}

Void main () {

INITFILE ();

Creatpcbline ();

Run ();

}

Design Notes :

This procedure is divided into three parts, initializes, creates a process, running the process, we do three people separately, I mainly do a function of creating a process.

That is, creatpcbline () in the main function.

Design experience:

The operating system is an indispensable system software in your computer system. It is an organizer of various resources in computer systems and organizers, commanders. The operating system adopts the time slice dispatch process, so that the system resources are fully utilized, users can spend less time to complete more work, this simulation system scheduling process, let me understand the scheduling method of system time films, The learning of the theory of operating system is more deep.

转载请注明原文地址:https://www.9cbs.com/read-19716.html

New Post(0)