2.1 Processes
2.1 Processes
2.1 Processes
2.1 Processes
2.2 Threads
2.3 Scheduling
2.4 Interprocess
communication
2.1 Processes
2
What is a process?
A process is basically a program in
execution. When a program is loaded into
the memory and it becomes a process, it
can be divided into four sections ─ stack,
heap, text and data. The following image
shows a simplified layout of a process
inside main memory.
3
The Process Model - 1
4
The Process Model - 2
• An operating system executes a variety of programs:
– Batch system – jobs
– Time-shared systems – user programs or tasks
• A process resources includes:
– Address space (text segment, data segment)
– CPU (virtual)
• program counter
In the simplest terms, a batch job is a
• registers
scheduled program that is assigned to run on
• stack a computer without further user interaction.
– Other resource Batch jobs are often queued up during
working hours, then executed during the
(open files, child processes…) evening or weekend when the computer is
idle.
5
Process Creation (1)
Principal events that cause process creation
1. System initialization (When an operating system is booted,
typically numerous processes are created. Some of these
are foreground processes).
2. Execution of a process-creation system call by running
process (Often a running process will issue system calls to
create one or more new processes to help it do its job).
3. User request to create a new process
4. Initiation of a batch job (users can submit batch jobs to the
system).
6
Process Creation (2)
• Address space
– Child duplicate of parent (When a process creates new process, a
duplicate of that process is created. This new process is called the child
and the process that created it is called the parent. The child process then
replaces the copy for the code the parent process created with the code the
child process is supposed to execute)
– Child has a program loaded into it
• UNIX examples
– fork system call creates new process
– exec system call used after a fork to replace the
process’ memory space with a new program
7
Process Creation (3) : Example
8
Process Termination
9
Process Hierarchies
10
Process States (1)
11
Process States (2)
13
Implementation of Processes (1)
To implement the process model, the operating system maintains a table (an
array of structures), called the process table , with one entry per process.
(Some authors call these entries process control blocks .) This entry contains
important information about the process’ state, including its program counter,
stack pointer, memory allocation, ...
Process Life Cycle
When a process executes, it passes through different states. These stages
may differ in different operating systems, and the names of these states are
also not standardized.
In general, a process can have one of the following five states at a time.
14
Implementation of Processes (2)
Process Control Block (PCB) - 1
15
Process Control Block (PCB) - 2
Process State: The current state of the process i.e., whether it is ready, running,
1
waiting, or whatever.
2 Process privileges: This is required to allow/disallow access to system resources.
3 Process ID: Unique identification for each of the process in the operating system.
4 Pointer: A pointer to parent process.
Program Counter: Program Counter is a pointer to the address of the next
5
instruction to be executed for this process.
CPU registers: Various CPU registers where process need to be stored for
6
execution for running state.
CPU Scheduling Information: Process priority and other scheduling information
7
which is required to schedule the process.
Memory management information: This includes the information of page table,
8
memory limits, Segment table depending on memory used by the operating system.
Accounting information: This includes the amount of CPU used for process
9
execution, time limits, execution ID etc.
10 IO status information: This includes a list of I/O devices allocated to the process.
Implementation of Processes (2)
The above figure shows some of the key fields in a typical system. The fields in
the first column relate to process management. The other two relate to memory
management and file management, respectively. It
Modeling Multiprogramming (1)
When multiprogramming is used, the CPU utilization can be improved.
Crudely put, if the average process computes only 20% of the time it is sitting in
memory, then with five processes in memory at once the CPU should be busy all
the time. This model is unrealistically optimistic, however, since it tacitly
assumes that all five processes will never be waiting for I/O at the same time.