Skip to content
Gallery
CS480 Notes
Share
Explore
Tasks/Study Notes

Chapter 2

Last edited 199 days ago by System Writer
Key Concept Mapping of Chapter 2
Section #
Description
Notes
1
2.1 Processes P.85
Processes are programs in execution, with their physical manifestation including memory pages containing data and instructions, hardware register values, program counter value, and more. Processes are in three states: running, ready, or blocked. Processes can be created by duplicating an existing process, except for the init process which is started directly by the kernel. In UNIX, a child process is created every time a command is typed at the shell. Processes can create child processes, which often work in conjunction with the parent process. A running process can be running in user mode or running in kernel mode. When a process dies, UNIX reassigns the parent PID of each of its children to the init process. The OS contains a virtual potpourri of data structures, one of which is the Process Table. The service routine is responsible for noticing which processes were blocked because a new event had been unavailable, and processes which were waiting for only that particular event would then have their state changed from 'sleeping' to 'ready'.
Open
2
Process management System Calls
Open
3
2.21 Thread Basics P 97
Threads are closely-cooperating entities that share the same memory space. When multiple threads are created, they share a common address space but have their own program counter, register values, and stack for the called procedures. Threads must be written carefully to ensure they do not harm other threads. Using several threads of execution on a multi-processor system may commandeer several CPUs simultaneously while on a single-CPU system, it may not speed things up. However, in some situations, threads may still provide a win, especially when programming a task that first requires a lot of number-crunching and then searching through a huge file to apply the results to that file. Creating threads is less expensive than forking a process since a thread mostly shares existing resources. The issue of whether to implement threads in user space or kernel space has various arguments for and against.
Open
There are no rows in this table

Chapter 2 Reading Notes

2.1 Processes

✨How to transform a single CPU into multiple virtual CPU’s✨
Sequential processes = Processes
A Processes is an instance of an executing program, including the current values of the program counter, registers, and variables.
Rapid switching back and forth to different processes = Multiprogramming
image.png

Four events cause processes to start:

System Initialization
Execution of a process-creation system call by a running process.
A user request to create a new process
Initiation of a batch job.
image.png
info

To Implement a process

The OS maintains a table (An Array of structures), called the Process Table, with one entry per process.
This entry contains important information about the process’ state, including its program counter, stack pointer, memory allocation, the status of its open files, its accounting and scheduling information, and everything else about the process that must be saved when the process is switched from running to ready or blocked state so that it can be returned to at at later time.
Conceptually, processes can be in three main states: running, ready, or blocked.
- A process that is actually using the CPU right now is 'RUNNING'.
- A process that capable of running [but is stopped because some other process is using the CPU right now]. is 'READY'.
-A process that is waiting for some external event is 'BLOCKED'.
(Blocked processes may be waiting for I/O, for some timer to go off, for some signal to arrive from another process, etc.)

How does an operating system know what a process is doing?

Process Execution

image.png
The following system calls are used for basic process management:
fork: A parent process uses fork to create a new child process. The child process is a copy of the parent. After fork, both parent and child execute the same program but in separate processes.
exec: Replaces the program executed by a process. The child may use exec after a fork to replace the process' memory space with a new program executable, making the child execute a different program than the parent.
exit: Terminates the process with an exit status.
wait: The parent may use wait to suspend execution until a child terminates. Using wait, the parent can obtain the exit status of a terminated child.

Process States

New → Ready → Running →
interrupted → Ready
I/O → Waiting → Ready
Running → Terminated

image.png

Process Control Block


Process Management


P1 Running. P2 Idle.
Cpu reg hold the value of state of P1
Interrupt P1.

fork()

take your currently running process and spawning a new process

exec()

fork() and exec()

Process vs Threads

Table
Process
Threads
1
A Program, + the state of all threads executing in that program
an action that performs some single task inside of a program
There are no rows in this table

Multithreading

image.png

Kernel level threads

Kernel level threads are supported and managed directly by the operating system.
The kernel knows about and manages all threads.
One process control block (PCP) per process.
One thread control block (TCB) per thread in the system.
Provide system calls to create and manage threads from user space.
Advantages
The kernel has full knowledge of all threads.
Scheduler may decide to give more CPU time to a process having a large number of threads.
Good for applications that frequently block.
Disadvantages
Kernel manage and schedule all threads.
Significant overhead and increase in kernel complexity.
Kernel level threads are slow and inefficient compared to user level threads.
Thread operations are hundreds of times slower compared to user-level threads.

User level threads

User level threads are supported above the kernel in user space and are managed without kernel support.
Threads managed entirely by the run-time system (user-level library).
Ideally, thread operations should be as fast as a function call.
The kernel knows nothing about user-level threads and manage them as if they where single-threaded processes.
Advantages
Can be implemented on an OS that does not suport kernel-level threads.
Does not require modifications of the OS.
Simple representation: PC, registers, stack and small thread control block all stored in the user-level process address space.
Simple management: Creating, switching and synchronizing threads done in user-space without kernel intervention.
Fast and efficient: switching threads not much more expensive than a function call.
Disadvantages
Not a perfect solution (a trade off).
Lack of coordination between the user-level thread manager and the kernel.
OS may make poor decisions like:
scheduling a process with idle threads
blocking a process due to a blocking thread even though the process has other threads that can run
giving a process as a whole one time slice irrespective of whether the process has 1 or 1000 threads
unschedule a process with a thread holding a lock.
May require communication between the kernel and the user-level thread manager (scheduler activations) to overcome the above problems.

User-level thread models

In general, user-level threads can be implemented using one of four models.
Many-to-one
image.png
One-to-one
image.png
Many-to-many
image.png
Two-level
image.png













sdfs

Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.