OS Class 3 Slides
OS Class 3 Slides
1 / 17
Program to Process
#include <stdio.h>
int main () {
$ gcc hello.c
$ ./a.out
Executable
Process
(a.out)
2 / 17
Process Concept
Multiple Parts
− the program code, also called text section
− Current activity including program counter, processor registers
− Stack containing temporary data
.. Function parameters, return addresses, local variables
− Data section containing global variables
− Heap containing memory dynamically allocated during run time
3 / 17
Process Concept(Contd ..)
4 / 17
Process in Memory
6 / 17
Beyond the Program Memory Map
OXFE00000
Kernel
(text, data, device
Kernel Process can access
memory
Heap
Data
(global and static)
Text
(Instruction)
0
7 / 17
Processes share the same Kernel but separate User Space
OXFE00000
OXFE00000
Kernel
Kernel
(text, data, device
(text, data, device
memory
Kernel Process can access
memory
Stack MAX_SIZE
Heap
Heap
Data
Data
Text
Text
(Instruction)
0 (Instruction) 0
Process 1 Process 2
Kernel
System call invokes a function in
the kernel using the trap
This causes
− Processor to shift from user
System Calls mode to priviledged mode or
kernel mode
On the completion of the system
User call, execution gets transferred
back to the user space
9 / 17
Example (Write System Call
trap
Trap Handler
Kernel
Space
Implementation
of write system
call
10 / 17
Process Creation
11 / 17
Tree of Processes in Linux
Unix Examples
fork() system call creates new process
exec() system call used after a fork() to replace the process’ memory
space with a new program
Figure 13 / 17
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())
− Process’ resources are deallocated by operating system
14 / 17
Process State
15 / 17
Diagram of Process State
16 / 17
Process Control Block (PCB)
17 / 17