Professional Documents
Culture Documents
Structure of process
Process states and transition
Context of process
Data structures of process
Components of context of process
Process creation, termination
Signals
A program in execution
Identifier
State
Priority
Program counter
Memory pointers
Context data
I/O status information
Accounting information
Contains
the
process
elements
Created and manage by
the operating system
Allows
support
for
multiple processes
10
11
Creation
New batch job
Interactive Login
Created by OS to
provide a service
Spawned by
existing process
Termination
Normal Completion
Memory
unavailable
Protection error
Operator or OS
Intervention
OSD, TE Computer, VIIT
12
13
14
15
User Running
interrupt,
interrupt return
4
Asleep
in
Memory
sleep
swap
out
Sleep, Swapped
reschedule
process
Ready to
Run in Memory
enough mem
Created
swap
out
wakeup
Preempted
Kernel
Running
preempt
wakeup
return
to user
return
Zombie
system call,
interrupt
swap
in
fork
16
17
Kernel Process
Table
Kernel Region
Table
A Process
Data
Stack
U Area
OSD, TE Computer, VIIT
18
U area
contains additional information that controls
operation of a process
further characteristics of the process only need
to be accessible to the running process itself
19
per process
region table
u area
Kernel
process table
main memory
20
21
Event descriptor
Used when the process is in the "sleep" state.
Scheduling parameters
Allow the kernel to determine the order in
which processes move to the states "kernel
running" and "user running
A signal field
keeps the signals sent to a process but not
yet handled
Various
timers:
process
resource utilization etc
execution
time,
22
23
I/O parameters
24
25
26
Region
Text
8K
Data 16K
Stack32K
a
Text
4K
Process
Data 8K
B
Stack
32K
27
28
8K
empty
Data 32K
137K
Stack 64K
852K
87K
764K
541K
552K
433K
783K
727K
333K
986K
941K
897K
1096K
Virtual Addresses
.
.
.
.
.
.
.
.
2001K
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
29
30
31
32
33
34
PC
PSW
SP
General purpose reg.
35
System level :
Static part
State of the process from PT
Dynamic part
36
37
38
39
40
41
42
43
Termination of process
Signals for process induced exceptions
Unrecoverable conditions during sys call
execution
Signals caused by unexpected error conditions
e.g writing a pipe that has no reader , illegal
ref. in lseek etc
Signals originated from process in UM e.g.
alarm
Related to terminal interaction
Tracing execution of process
OSD, TE Computer, VIIT
44
Shell basics
Shell types
First shell script
Logic : if
Logic : for
Logic : while
45
INPUT
shell
OUTPUT
ERROR
OSD, TE Computer, VIIT
46
Any Program
47
/bin/sh
/bin/bash
Bourne-Again Shell
48
C Shell (/bin/csh)
Turbo C Shell (/bin/tcsh)
Korn Shell (/bin/ksh)
49
C Shell (/bin/csh)
Turbo C Shell (/bin/tcsh)
Korn Shell (/bin/ksh)
50
51
A Text File
With Instructions
Executable
52
53
% ./hello.sh
echo vs. /usr/bin/echo
% echo $PATH
/bin:/usr/bin:/usr/local/bin:
/home/borwicjh/bin
% which echo
/usr/bin/echo
54
% hello.sh
bash: hello.sh: Command not found
% PATH=$PATH:.
% hello.sh
Hello, world
55
% echo $USER
$USER
% echo $USER
borwicjh
% echo \
% echo deacnet\\sct
deacnet\sct
% echo \
\
56
57
% echo This \
Is \
A \
Very \
Long \
Command Line
This Is A Very Long Command Line
%
58
$?
0 is True
% ls /does/not/exist
% echo $?
1
% echo $?
0
59
60
%
%
0
%
%
1
test 1 -lt 10
echo $?
test 1 == 10
echo $?
61
% echo $(( 1 + 2 ))
3
% echo $(( 2 * 3 ))
6
% echo $(( 1 / 3 ))
0
62
if [ $USER eq borwicjh ]
then
:
# elif a contraction of else if:
elif ls /etc/oratab
then
:
else
then
:
fi
63
64
for i in 1 2 3
do
echo $i
done
65
for i in /*
do
echo Listing $i:
ls -l $i
read
done
66
a=0; LIMIT=10
while [ "$a" -lt "$LIMIT" ]
do
echo -n "$a
a=$(( a + 1 ))
done
67
#!/bin/bash
echo "enter maximum number
read n
# taking input from user
echo "enter Numbers in array:
for (( i = 0; i < $n; i++ ))
do
read nos[$i]
done
#printing the number before sorting
echo "Numbers in an array are:
for (( i = 0; i < $n; i++ ))
do
echo ${nos[$i]}
done
68
69
OUTPUT:
pavan@pavan-desktop:~$bash BubbleSort.sh
enter maximum number
4
enter numbers in array:
4
1
0
3
70
71
Concepts
Various threading models
Fork() & exec() system call
Thread library
Thread cancellation
Thread specific data
72
It shares with other threads belonging to the same process its code section,
data section, and other OS resources, such as open files and signals
A traditional (or heavyweight) process has a single thread of control
If a process has multiple threads of control, it can perform more than one
task at a time. Threads are a way for a program to split itself into two or
more simultaneously running tasks. That is the real excitement surrounding
threads
OSD, TE Computer, VIIT
73
74
75
76
77
CPU2
CPU1
CPU2
CPU1
CPU2
Time
OSD, TE Computer, VIIT
78
Stack 1
Heap
Address Space
Stack 2
Global Data
Code
OSD, TE Computer, VIIT
79
80
Responsiveness
Resource Sharing
Economy
Utilization of MP Architectures
81
82
83
Examples
Windows XP/2000
Solaris
Linux
Tru64 UNIX
Mac OS X
84
thread
85
86
87
Advantages
Thread switching does not involve kernel no mode switching
Scheduling
algorithm
can
be
application
specific
choose
best
Disadvantages
Most system calls are blocking and the kernel blocks processes
all threads within the process will be blocked
Kernel can only assign processes to processors threads
within same process cannot run simultaneously on processors
88
89
Because each kernel thread is actually a different kernelschedulable entity, multiple threads can run concurrently on
different processors
Can achieve significant speedups
uniprocessors to multiprocessors
when
migrated
from
90
kernel threads
91
92
sum =
i=0
93
#include <pthread.h>
#include <stdio.h>
int sum; //this data is shared by the thread(s)
94
int i;
sum = 0;
if (upper > 0) {
for (i = 1; i <= upper; i++)
sum += i;
}
pthread_exit(0);
}
95
Asynchronous or deferred
Signal handling
Thread pools
Thread-specific data
Scheduler activations
96
97
98
Options:
Deliver the signal to the thread to which the signal
applies
Deliver the signal to every thread in the process
Deliver the signal to certain threads in the process
Assign a specific thread to receive all signals for the
process
99
10
0
10
1
10
2
10
3
Concepts
Principles of deadlock
Deadlock strategies
Prevention
Avoidance
Detection
Recovery
Ostrich algorithm
Bankers algorithm
10
4
No efficient solution
10
5
I need
quad C
and B
I need
quad B
and C
I need
quad A
and B
I need
quad D
and A
OSD, TE Computer, VIIT
10
6
HALT until
D is free
HALT until
C is free
HALT until
B is free
HALT until
A is free
10
7
10
8
10
9
11
0
11
1
11
2
11
3
11
4
11
5
Hold-and-wait
A process may hold allocated resources while
awaiting assignment of others
No pre-emption
No resource can be forcibly removed from a
process holding it
11
6
11
7
11
8
11
9
12
0
12
1
Mutual Exclusion
No Preemption
Circular Wait
12
2
12
3
12
4
12
5
12
6
12
7
12
8
12
9
13
0
13
1
13
2
13
3
Deadlock prevention
conservative;
strategies
are
very
13
4
13
5
13
6
About Android
Android boot process / sequence
137
13
8
13
9
Step 2 : bootloader
Bootloader is small program which runs before
Android operating system running
Popular bootloader - redboot, uboot, qi bootloader
Android bootloader can be found at - <Android
Source>\bootable\bootloader\legacy\usbloader
14
0
Step 3 : kernel
<android
<android
14
1
14
2
1.
2.
3.
4.
5.
6.
7.
14
3
8. Write short notes on popular thread library (For eg, POSIX, Java, Win32)
9. What do you understand by deadlock? How deadlock can be prevented?
10. What do you understand by deadlock? How deadlock can be avoided?
11. What do you understand by deadlock? How deadlock can be detected?
12. Is deadlock prevention is better than deadlock avoidance ? Justify your
answer
13. Explain with example Banker algorithm
14. Write notes on ostrich algorithm
15. Explain in details six steps of Android boot process
14
4
www.wfu.edu/~borwicjh/presentations/UNIX
Shell-Scripting
Basics.ppt
[4] cse.stfx.ca/~mlin/cs375/lectures/thread.ppt
[5]
http://www.kpbird.com/2012/11/in-depth-android-boot-sequence-
process.html
14
5
Thank You
OSD, TE Computer, VIIT
14
6