Process Management
Process Management
MANAGEMENT
Tiến trình 2
Sẵn sàng PCB PCB PCB
Tiến trình 3
….
Tiến trình n PCB n Chờ đợi đọc đĩa PCB PCB
▪ Advantages:
▪ Switching threads does not require switching to kernel
mode => saves time
▪ The application can be moderated according to its own
characteristics, regardless of the moderation of the OS
▪ Can be used on OS that do not support multi-threading
▪ Disadvantages:
▪ When a thread calls a system call and is blocked, the
entire process is blocked
▪ => does not allow to take advantage of the
responsiveness of the multi-threaded model
▪ Doesn't allow taking advantage of multi-CPU
architectures because the OS distributes CPUs for the
whole process, not for specific threads
chế độ chế độ
người dùng người dùng
chế độ chế độ
nhân nhân
P tiến trình
state
www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH
Trang 30
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
III. Process scheduling
2. Types of scheduling
2. Scheduling with redistribution and non-
redistribution:
▪ Scheduling with redistribution:
▪ OS can use a kill mechanism to reclaim the CPU of a process
that is in a running state.
▪ Scheduling with non-redistribution:
▪ Processes that are in the running state will be CPU used until
one of the following scenarios occurs:
▪ Closing process
▪ The process must go to a waiting state due to I/O execution.
▪ => Cooperative Scheduling: because it is only possible when
the process is cooperative and the CPU is ceded.
▪ If the process is not cooperative, use infinite CPU => other
processes that are not CPU-provisioned (Windows 96, NT)
www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH
Trang 31
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
III. Process scheduling
2. Types of scheduling
5. Response time:
▪ This is a user-oriented criterion and is often used in live
interaction systems.
6. Predictability:
▪ The life cycle, waiting time, response time must be stable,
independent of the load of the system.
7. Fairness:
▪ Processes of the same priority must be treated equally
▪ Limited waiting
www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH
Trang 61
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
IV. SYNCHRONIZE PROCESSES SIMULTANEOUSLY
3. Peterson Algorithm(tt)
▪ x.cwait():
▪ The process is in the monitor and calls the cwait blocked until
condition x occurs
▪ The process is queued by the condition variable x
▪ The monitor is released and another process will be entered.
▪ x.csignal():
▪ The process of calling csignal to notify that condition x has been
satisfied
▪ If there is a process that is being blocked and is in the queue of x
due to the previous call to x.cwait() it will be freed
▪ If there is no blocked process, the csignal operation will have no
effect at all
www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH
Trang 81
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
IV. SYNCHRONIZATION OF SIMULTANEOUS PROCESSES
7. Monitor (tt)
Monitor
Dữ liệu cục bộ
condition y
product take ( ) {
if (count == 0)
notEmptry.cwait (); //chờ đến khi buffer không rỗng
<Lấy một sản phẩm x từ buffer>
count --;
notFull.csignal ( );
}
}
▪ No redistribution:
▪ Option 1:
▪ When a process requests resources but can't because they've been
allocated, the OS reclaims all the resources it holds
▪ The process can only be continued after the old resource is obtained
along with the new required resource.
▪ Option 2:
▪ When the progress requires resources, if available, they will be allocated
immediately
▪ If a resource is held by another process and this process is waiting to
grant more resources, it will be withdrawn to grant the requested process
▪ If both of the above conditions are not met, the process of requesting
resources must wait
www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH
Trang 93
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
V. Deadlock
3. Deadlock Prevention (tt)
▪ Circle waiting:
▪ Define the order for resource types and allow the resource request
process only so that the resource that the next request process has
an order greater than the resource it requested first
▪ Suppose in the system there are n types of symbol resources R1,
R2, ..., Rn
▪ Suppose these types of resources are arranged in ascending order
of the index
▪ If the process has requested some Ri-type resource, then the
process is only allowed to request an Rj resource if j > i
▪ If a process needs multiple resources of the same type, it must
request all resources of that type at the same time
www.ptit.edu.vn GIẢNG VIÊN: THS NGUYỄN THỊ NGỌC VINH
Trang 94
BỘ MÔN: KHOA HỌC MÁY TÍNH – KHOA CNTT1
V. deadlock
4. Preventing Deadlocks
▪ Deadlock prevention solutions focus on using
rules or constraints to prevent deadlocks.
Disadvantages: make the use of resources
inefficient, reduce the efficiency of the process.
▪ Preventing deadlocks:
▪ Use rules or constraints when allocating resources to
prevent deadlocks
▪ Inefficient use of resources, reducing process
efficiency
▪ Deadlock Detection:
▪ In case each resource type has only one resource => use a graph
that represents the relationship between the two waits in the
middle of the process
▪ Build a resource allocation graph:
▪ Nodes are progress and resources
▪ A resource is connected to a process by a
directed arc if the resource is granted to that
process
▪ A process is connected to a resource with a
directional arc if the process is being allocated
that resource