Processes and Threads Ch2
Processes and Threads Ch2
What is a process
• Informally: program in execution
• Process state
– The program code, also called text section
Processes and Threads – Registers (including PC, SP)
– Stack containing temporary data
– Data section containing global variables
– Heap containing memory dynamically allocated during
run time
– Open file tables
Some slides and/or pictures are adapted from • Key concept: processes are separated: no
• Operating System Concepts, 9th edition, by Silberschatz, Galvin,
Gagne, John Wiley & Sons, 2013 process can directly affect the state of another
• Lecture notes by Dr. Prof. John Kubiatowicz (Berkeley)
1 process. 2
1 2
Process in Memory
Examples of Processes
• Shell: creates a process to execute
command
> ls foo
(shell creates process that executes “ls”)
• When you execute a program you have
just compiled, the OS generates a process
to run the program.
• Your WWW browser is a process.
4
3 4
Uniprogramming vs
Process vs. Program
Multiprogramming
• Program: static • Uniprogramming
• Process: dynamic – Only one process exists at any point
• Example: – Makes designing OS easier
– A user opens two browser windows: same – User can’t do two things at once (MS-DOS)
program, different processes; • Multiprogramming
– Multiple processes exist (only one runs at a
time)
– Requires protection, scheduling, etc
5 6
5 6
1
2/28/2019
7 8
9 10
11 12
2
2/28/2019
• To start a process
login
pid = 8415
kthreadd sshd
pid = 3028
– Load code and data (from a file)
pid = 2
14
13 14
15 16
17 18
3
2/28/2019
Process Termination
Process Termination
• Process executes last statement and then asks the
operating system to delete it using the exit()
system call.
– Returns status data from child to parent (via wait()) Conditions which terminate processes
– Process’ resources are deallocated by operating system
• Parent may terminate the execution of children 1. Normal exit (voluntary)
processes using the abort() system call. Some
reasons for doing so: 2. Error exit (voluntary)
– Child has exceeded allocated resources 3. Fatal error (involuntary)
– Task assigned to child is no longer required
– The parent is exiting and the operating systems does not 4. Killed by another process (involuntary)
allow a child to continue if its parent terminates
20
19 20
21 22
23 24
23 24
4
2/28/2019
25 26
25 26
27
27 28
29 30
5
2/28/2019
31 32
Address Space
Embedded systems Mach, OS/2, Linux, – How do we position stacks
(Geoworks, VxWorks, Win 95?, Mac OS X, relative to each other?
Many JavaOS,etc)
Win NT to XP, Solaris, – What maximum size should we
JavaOS, Pilot(PC) HP-UX choose for the stacks? Heap
• Real operating systems have either – What happens if threads violate
this? Global Data
– One or many address spaces
– One or many threads per address space – How might you catch violations? Code
33 34
35 36
6
2/28/2019
Ready Queue And Various I/O Device Queues Representation of Thread Scheduling
• Thread not running TCB is in some scheduler queue
– Separate queue for each device/signal/condition
– Each queue can have a different scheduler policy Queueing diagram represents queues, resources, flows
37 38
39 40
39 40