Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Midterm Test

Student’s name: Nguyễn Ngọc Chiến


ID: 22IT035

Q1 (3.0 points): Explain the following 3 states process diagram?


Describe about scheduling for proccesses? Give an example?

A three-state process model is a model that describes the different states that
a process can go through in its lifetime. The three states are:
- New: This is the state where a process is being created.
- Ready: This is the state where a process is waiting to be executed.
- Running: This is the state where a process is being executed.

The process flow diagram also shows the events that can cause a process to
move from one state to another. These events are:
- New: This is the event that occurs when a process is created.
- Dispatch: This is the event that occurs when a process is selected to be
executed.
- Start: This is the event that occurs when a process begins execution.
- Block: This is the event that occurs when a process is suspended to wait for
an event to occur.
- Resume: This is the event that occurs when a process is continued after
being blocked.
- Exit: This is the event that occurs when a process terminates.

New
When a process is created, it is in the new state. In this state, the process is
allocated memory and other resources needed for execution.

Ready
When a process is created, it moves to the ready state. In this state, the
process is waiting to be selected for execution.

Running
When a process is selected for execution, it moves to the running state. In this
state, the process is executing its instructions.

Blocked
When a process needs to wait for an event to occur, it moves to the blocked
state. In this state, the process will not be executed until the event occurs.
When a process is waiting for an event to occur, it is said to be suspended.

Resume
When the event that a process is waiting for occurs, the process moves to the
resume state. In this state, the process will continue executing its instructions.

Exit
When a process terminates, it moves to the exit state. In this state, the process
has released all of its resources and no longer exists.

Process Scheduling
Process scheduling is the process of selecting the next process to be
executed. There are many different scheduling algorithms that can be used to
select the next process to be executed. Some common scheduling algorithms
include:
- First-Come First-Served (FCFS): This algorithm selects the next process to
be executed based on the order in which it arrived in the ready queue.
- Shortest Job First (SJF): This algorithm selects the next process to be
executed based on the shortest amount of time it will take to complete.
- Round Robin: This algorithm selects the next process to be executed based
on a round-robin fashion.
Example:
A process is created to print a document. The process goes through the
following states:
- New: The process is created.
- Ready: The process waits to be executed.
- Running: The process starts printing.
- Block: The process waits for disk access.
- Resume: The process continues printing.
- Exit: The process terminates.

Q2 (3.0 points):
In the console or terminal window, type the following LINUX commands on
the command line. Note and write down the results (capture screen images)
$ ls
$ pwd
$ps
$ cd ..
$ pwd
$ cd /usr/local

$ su -i
$ useradd <Studentls Name>
$ cat /etc/passwd
$ adduser <Student’s FullName>
$ cat etc/passwd
$ su <Student’s FullName>
$ pwd
$l
Q3 (2.0 points): A memory free in 4 frames. How many page faults do occur
after running as the following page 2 3 2 0 1 5 2 4 5 3 2 5 2 using LRU
Answer:

2 3 2 0 1 5 2 4 5 3 2 5 2
F1 2 2 2 2 2 2 2 2 2 2 2 2 2
F2 3 3 3 3 5 5 5 5 5 5 5 5
F3 0 0 0 0 4 4 4 4 4 4
F4 1 1 1 1 1 3 3 3 3
PF * * * * * * *
Page fault: 7

Here's a breakdown of the page table entries and faults:


2 (no fault, empty frame)
3 (no fault, empty frame)
2 (page already in memory, no fault)
0 (page fault, replace least recently used - 3)
1 (page fault, replace least recently used - 2)
5 (page fault, replace least recently used - 0)
2 (page already in memory, no fault)
4 (page fault, replace least recently used - 1)
5 (page fault, replace least recently used - 2)
3 (page already in memory, no fault)
2 (page already in memory, no fault)
5 (page fault, replace least recently used - 4)
2 (page already in memory, no fault)
There are 7 instances where a page fault occurs because the needed page
isn't in memory and the LRU algorithm replaces the least recently used page
to make space.

Q4 (2.0 ponts): A memory free in 3 frames. How many page fault occur after
running as the following page 7, 0 , 1, 2 , 0, 3, 0 , 4, 2 , 3 , 0 , 3 , 2 , 1, 2, 0, 1,
0 , 7 using FIFO

7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 0 7
F1 7 7 7 2 2 2 2 4 4 4 0 0 0 0 0 0 0 0 7

F2 0 0 0 0 3 3 3 2 2 2 2 2 1 1 1 1 1 1

F3 1 1 1 1 0 0 0 3 3 3 3 3 2 2 2 2 2

PF * * * * * * * * * * * * *

Page table:
| Page number | Frame number |
|---|---|
|7|0|
|0|1|
|1|2|

Frames:

| Frame number | Page number |


|---|---|
|0|7|
|1|0|
|2|1|
Page faults:

* 7 (page not in memory)


* 0 (page not in memory)
* 1 (page not in memory)
* 2 (page not in memory)
* 0 (page not in memory)
* 3 (page not in memory)
* 0 (page not in memory)
* 4 (page not in memory)
* 2 (page evicted)
* 3 (page evicted)
* 0 (page not in memory)
* 3 (page evicted)
* 2 (page evicted)
* 1 (page evicted)
* 2 (page evicted)
* 0 (page not in memory)
* 1 (page evicted)
* 0 (page not in memory)
* 7 (page evicted)
Page fault: 13

You might also like