Content-Length: 3095314 | pFad | https://www.scribd.com/document/733925291/CS211-Lec-5
7CS211 Lec 5
CS211 Lec 5
CS211 Lec 5
Lecture # 5
Agenda for Today
Process concept
Process scheduling concepts
Process creation and termination
Process management in UNIX/Linux— system calls:
fork, exec, wait, exit
What is a process?
Process – a program in execution; process execution must progress in
sequential fashion.
A process consists of:
Code (text) section: the executable code
Data section: global variables
Stack section: temporary data storage when invoking functions
Heap section: memory that is dynamically allocated during program
run time
Environment
CPU state (program counter, etc.)
Process control block (PCB)
The status of the current activity of a process is represented by the value
of the program counter and the contents of the processor’s registers.
CPU and I/O Bound Processes
Processes can be:
I/O-bound process – spends more time doing I/O than
computations, many short CPU bursts.
I/O Burst CPU Burst I/O Burst CPU Burst
Medium-term scheduler
Schedulers
A process migrates between the various scheduling queues throughout
its lifetime. The operating system must select, for scheduling purposes,
processes from these queues in some fashion. The appropriate
scheduler carries out this selection process.
The Long-term scheduler (or job scheduler) selects which processes
should be brought into the ready queue, from the job pool that is the
list of all jobs in the system.
The Short-term scheduler (or CPU scheduler) selects which process
should be executed next and allocates CPU.
Long Term Scheduler
Long-term scheduler (or job scheduler) – selects processes from
the job pool to be brought into the ready queue.
• Long-term scheduler is invoked very infrequently
• The long-term scheduler controls the degree of multiprogramming.
• More processes, smaller percentage of time each process is
executed
Short Term Scheduler
Short-term scheduler (or CPU scheduler) – selects which process should be
executed next and allocates it the CPU through the dispatcher.
• Short-term scheduler is invoked very frequently
• Invoked when following events occur
o CPU slice of the current process finishes
o Current process needs to wait for an event
o Clock interrupt
o I/O interrupt
o System call
o Signal
Medium Term Scheduler
Also known as swapper
Selects an in-memory process and swaps it out to
the disk temporarily
Swapping decision is based on several factors
• Arrival of a higher priority process but no memory
available
• Poor mix of jobs
• Memory request of a process cannot be met
Addition of Medium Term Scheduling
Process Creation
Parent process create children processes, which, in turn create other
processes, forming a tree of processes.
Resource sharing
Parent and children share all resources.
Children share a subset of parent’s resources.
Parent and child share no resources.
When a process creates a new process, two possibilities for execution
exist:
1.The parent continues to execute concurrently with its children.
2.The parent waits until some or all of its children have terminated.
Processes Tree on a UNIX System
Process Creation …
There are also two address-space possibilities for the new process:
1. The child process is a duplicate of the parent process (it has
the same program and data as the parent).
2. The child process has a new program loaded into it.
UNIX examples
fork() system call creates a new process
exec() system call used after a fork to replace the process’
memory image with a new executable.
Process Management in UNIX/Linux
The parent is exiting, and the operating system does not allow
a child to continue if its parent terminates.
Reference & Reading Material
• Operating Systems Concepts,
Chapter 3 “Processes”
29
Fetched URL: https://www.scribd.com/document/733925291/CS211-Lec-5
Alternative Proxies: