Вы находитесь на странице: 1из 32

Module 5

1
Process
• A process consists of executable program
(codes), state of which is controlled by OS,
• The state during running of a process─
represented by process-status (running,
blocked, or finished), processs structure—its
data, objects and resources, and process
control block (PCB).

2
Process State Switching 5-states model
• Runs when it is scheduled to run by the OS (kernel)
• OS gives the control of the CPU on a process’s request (system
call).
• Runs by executing the instructions and the continuous
changes of its state takes place as the program counter (PC)
changes
new
new admitted
exit terminated
interrupt

running
ready

Scheduler
I/O or
dispatch I/O or
event
event wait
completion

waiting
3
• Runs when it is scheduled to run by the OS
(kernel)
• OS gives the control of the CPU on a process’s
request (system call).
• Runs by executing the instructions and the
continuous changes of its state takes place as
the program counter (PC) changes

4
• Process is that executing unit of computation,
which is controlled by some process (of the
OS) for a scheduling mechanism that lets it
execute on the CPU and by some process at
OS for a resource management mechanism
that lets it use the system-memory and other
system resources such as network, file, display
or printer

5
• Application program can be said to consist of
number of processes

6
Example ─ Mobile Phone Device
embedded software

• Software highly complex.


• Number of functions, ISRs, processes threads,
multiple physical and virtual device drivers,
and several program objects that must be
concurrently processed on a single processor.

7
Exemplary processes at the phone device

• Voice encoding and convoluting process─ the


device captures the spoken words through a
speaker and generates the digital signals after
analog to digital conversion, the digits are
encoded and convoluted using a CODEC,
Modulating process,Display process,
• GUIs (graphic user interfaces), and Key input
process ─ for provisioning of the user interrupts

8
9
PCB
• A data structure having the information using
which the OS controls the process state.
• Stores in protected memory area of the
kernel.
• Consists of the information about the process
state

10
Information about the process state
at Process Control Block…
• Process ID,
• process priority,
• parent process (if any),
• child process (if any), and
• address to the next process PCB which
• will run,

11
Thread

• A thread consists of executable program


(codes), state of which is controlled by OS,
• The state information─ thread-status
(running, blocked, or finished), thread
structure— its data, objects and a subset of
the process resources, and thread-stack

12
Thread …lightweight
• Considered a lightweight process and a
process level controlled entity.
• [Light weight means its running does not
depend on system resources]

13
Process..heavyweight
• Process considered as a heavyweight process
and a kernel-level controlled entity.
• Process thus can have codes in secondary
memory from which the pages can be
swapped into the physical primary memory
during running of the process.
[Heavy weight means its running may depend on
system resources]

14
Threads of a Process sharing Process
Structure

15
Process Thread
Process vs.Thread
Process is considered heavy weight Thread
is considered light weight

Unit of Resource Allocation and of Unit of CPU utilization


protection

Process creation is very costly in terms Thread creation is very economical


of resources

Program executing as process are Programs executing using thread are


relatively slow comparatively faster

Process cannot access the memory area Thread can access the memory area
belonging to another process belonging to another thread within the
same process

Process switching is time consuming Thread switching is faster

One Process can contain several threads One thread can belong to exactly one
process
16
• Application program can be said to consist of
number of threads or processes

17
Multiprocessing OS

• A multiprocessing OS runs more than one


processes.

18
Example ─ Multiple threads of Display
process in Mobile Phone Device

• Display_Time_Date thread ─ for displaying


clock time and date.
• Display_Battery thread ─ for displaying
battery power.
• Display_Signal thread ─ for displaying signal
power for communication with mobile service
provider.

19
• Display_Profile thread ─ for displaying silent or
sound-active mode. A thread
• Display_Message thread ─ for displaying
unread message in the inbox.
• Display_Call Status thread ─for displaying call
status; whether dialing or call waiting

20
Thread and Task

• Thread is a concept used in Java or Unix.


• A thread can either be a sub-process within a
process or a process within an application
program.
• To schedule the multiple processes, there is
the concept of forming thread groups and
thread libraries

21
Task
• Task ─ term used for the process in the RTOS for the
embedded systems.
• An application program consist of the tasks and task
behaviors in various states that are controlled by OS.
• A task is like a process or thread in an OS.
• Runs when it is scheduled to run by the OS (kernel),
which gives the control of the CPU on a task request
(system call) or a message.
• Runs by executing the instructions and the continuous
changes of its state takes place as the program
counter (PC) changes
• A task─ an independent process. No task can call
another task. 22
Task…
• Includes task context and TCB
• TCB ─ A data structure having the information using
which the OS controls the process state.
• Stores in protected memory area of the kernel.
• Consists of the information about the task state

23
Task…
• TaskID, e.g. a number
between 0 and 255

24
Task States
1. Idle state [Not attached or not registered]
2. Ready State [Attached or registered]
3. Running state
4. Blocked (waiting) state
5. Delayed for a preset period
• Number of possible states depends on the RTOS.

25
• A thread does not call another thread to run.
• A task also does not directly call another task
to run.
• Multithreading needs a thread-scheduler.
• Multitasking also needs a task-scheduler.

26
Timer Functions

• Real time clock─ system clock, on each tick


SysClkIntr interrupts
• Based on each SysClkIntr interrupts─ there
are number of OS timer functions
• OS_TICK_PER_SEC─ to set the system clock
ticks and hence SysClkIntr interrupts per s
• OSTickInit ( )─ to initiate system clock ticks

27
• OSTimeDelay ( )─ to delay the process making call by
a fixed number of system clock ticks specified in
argument
• OSTimeDelay-Resume ( )─ to resume a delayed
process specified in the argument
• OSTimeSet ( )─ to set the counts of system clock ticks
• OSTimeGet ( ) ─ to read the counts of system clock
ticks to find the time interval from the previous read
or write of the counts

28
Scheduling
• Scheduling implies selection of a process for
execution in a way to meet the objective of
the system (throughput, response time, etc.)
• Scheduler is the program responsible for
scheduling

29
Scheduling Criteria
• Turn around Time
– Interval of time between submission & completion
• Waiting Time
– Time spent waiting in ready queue
• Response Time
– Time from submission until response received
• CPU Utilisation
– Keep busy
• Throughput
– Number of process completed per unit time
• Fairness
– No process should starve
• Enforcing Priorities
– Scheduling policy should favors higher priority process 30
Scheduling Algorithms
• Non Preemptive Mode: process would be taken away from the processor if
any one of the following events occur
– Its completion
– It requires some I/O
– It executes a system call
1. FCFS (First Come First Serve)
2. SJF(Shortest Job First)
3. Priority
• Preemptive Mode: process would be taken away from the processor if any
one of the following events occur
– Timeout occurs
– Arrival of new process with higher priority
1. Round Robin
2. SRT (Shortest Remaining Time)
3. Priority 31
Process Cooperation by Communication
(Inter-Process Communication)
• Various processes participate in common effort that link all the
processes.
• Communication can be characterized as consisting of message of
some sort.
• Nothing is shared between processes in the act, so mutual exclusion
is NOT a control requirement
• Concurrency mechanisms for inter-process communication and
synchronization
– Queue to communicate data
– Mailbox/Messages ”
– Pipes and Sockets ”
– Semaphores to trigger actions
– Signals ”
– Remote Procedure Call (RPC) for distributed systems 32

Вам также может понравиться