Processes
Processes
Processes
Operating System Objectives
• Convenience
Makes the computer more convenient to use
• Efficiency
Allows computer system resources to be
used in an efficient manner
• Ability to evolve
Permit effective development, testing, and
introduction of new system functions without
interfering with service
2
Main OS Concepts
• Processes
• Memory Management
• Information protection and security
• Scheduling and resource
management
• System structure
3
What is a Process?
4
Figure 3.1 Process in memory
5
Figure 3.1 Process in memory.
A process includes:
Text: Contain program counter – specifying next
instruction to be executed under that process.
Data section: Containing global variables.
Heap: Which is memory that is dynamically allocated
during process run time.
Stack: Contains temporary data (such as function
parameters, return addresses, and local variables).
6
Cont.
7
Cont.
8
3.1.2 Process State
10
3.1.3 Process Control Block
11
Cont.
12
3.2.1 Scheduling Queues
A new process is initially put in the ready queue. It waits there until it is
selected for execution, or dispatched.
Once the process is allocated the CPU and is executing, one of several events
could occur:
1.The process could issue an I/O request and then be placed in an I/O queue.
2.The process could create a new child process and wait for the child’s
termination.
3.The process could be removed forcibly from the CPU, as a result of an
interrupt, and be put back in the ready queue.
In the first two cases, the process eventually switches from the waiting state
to the ready state and is then put back in the ready queue. A process continues
this cycle until it terminates, at which time it is removed from all queues and
has its PCB and resources deallocated.
15
3.2.2 Schedulers
16
Types of Scheduler
17
Cont.
Medium-term scheduler :
Some operating systems, such as time-sharing systems, may introduce an
additional, intermediate level of scheduling.
The key idea behind a medium-term scheduler is that sometimes it can be
advantageous to remove a process from memory (and from active
contention for the CPU) and thus reduce the degree of
multiprogramming.
Later, the process can be reintroduced into memory, and its execution can
be continued where it left off. This scheme is called swapping.
The process is swapped out, and is later swapped in, by the medium-term
scheduler.
18
Cont.
19
3.3.1 Process Creation
20
3.3.1 Process Creation
Figure 3.8 illustrates a typical process tree for the Linux operating system,
showing the name of each process and its pid. (We use the term process rather
loosely, as Linux prefers the term task instead.) The init process (which always
has a pid of 1) serves as the root parent process for all user processes. Once the
system has booted, the init process can also create various user processes, such
as a web or print server, an ssh server, and the like.
21
Cont.
22
3.3.2 Process Termination
23
Cont.
A parent may terminate the execution of one of its children for a variety of
reasons, such as these:
»The child has exceeded its usage of some of the resources that it has been
allocated. (To determine whether this has occurred, the parent must have a
mechanism to inspect the state of its children.)
»The task assigned to the child is no longer required.
»The parent is exiting, and the operating system does not allow a child to
continue if its parent terminates.
Some systems do not allow a child to exist if its parent has terminated. In
such systems, if a process terminates (either normally or abnormally), then
all its children must also be terminated. This phenomenon, referred to as
cascading termination, is normally initiated by the operating system.
24
3.4 Interprocess Communication
25
Cont.
27
Cont.
1. Shared memory
2. Message passing
28
3.4.1 Shared-Memory Systems
29
Cont.
30
Cont.
31
3.4.2 Message-Passing Systems
32
Cont.
33
Cont.
34