1. PROGRAM EXECUTION
BASIC FLOW OF COMPILATION
When a programmer writes code in any language say
c/c++/python this code is called source code.
But,computer dont understand this,it understands only
binary language i.e machine language.so this source code
have to be converted into binary form.the software used
for this is called translation software.
Source
code
Binary
form
execution
2. TYPES OF TRANSLATION SOFTWARE
COMPILER
INTERPRETER
COMPILER
Compiler takes the complete source code and it
will convert it into machine code at once.
Steps in compilation-:
1)Preprocessing 2)compilation 3)Assembly
4)Linking
3. Preprocessing Phase-
- removes comments
- Imports all the modules
- Carries out all the preprocessing directives.
Compilation Phase-
1.)analysis Phase-
-smallest indivisible unit in a program is called
token...eg.keywords,identifiers,literals.
-This phase recognizes all the tokens ,and creates a
symbol table out of it.
4. Synthesis Phase-
==Syntax tree is a tree that represents all the constructs of the source code in
the form of a tree.
==Basically all the operators are placed on the root node and the operands
are placed on the leaf nodes.
==This phase generates this syntax tree.
==If any error is there ,it will be reported as error.
Once the code is error free,it is converted into assemby language code called
Intermediate code.
Eg-:4*5+9
*
+
9
4
5
5. Assembly Phase-
This phase converts the assembly level instructions to equivalent
machine code called object code
Linking-all the required libraries are loaded with the help of
Linker.
Loader-It is a part of compiler that loads all the instruction
into memory for execution.
COMPLETE COMPILATION PROCESS
assembly machine
Source
code
analy
sis
synth
esis
Object
code
libraries Executable
6. INTERPRETATION PROCESS
==It analyses each line of code ,converts it into object code ,adds
required libraries and runs it.
==The first line of code is executed ,yet before second line of
code is converted to object code.
WORKING OF INTERPRETER
code1
code2
code3 interpreter
10101010
10101101
10110110
7. DIFFERENCE BETWEEN COMPILER AND INTERPRETER
• COMPILER INTERPRETER
• takes entire program - takes single line of code
•
generates intermediate code - does not generate
takes more memory - takes less memory
displays the list of errors - display error in single line
no,once the work is done,it - always required
is no more required
INPUT
OUTPUT
MEMORY
ERRORS
Always
required
8. ROLE OF OPERATING SYSTEM IN RUNNING A PROGRAM
• OS as a resource manager-
A program when not running lies on the disk.
To execute it,is loaded into memory then it becomes process
==To manage resources(to improve efficiency)
==When a running process needs I/O ,then CPU sits idle ,at that
moment,another process is loaded into memory to improve
efficiency.. Called throughput
THROUGHPUT =
Time taken
NO.of job
completed
9. To mange multiple functions OS provides following
functions
Process Management-
Once the program is loaded into memory it becomes process.and it is
allocated memory as shown below
Stack
Heap
Global
variables
Program
code
Area used for function
calls,arguments etc
Area used for dynamic
allocation of memory
Comiled code and global
variables are stored here
10. State diagram of a process
START-when the process first loaded into memory
READY-when the process ready for the CPU to be allocated
RUNNING-when the process is allocated CPU
WAITING-when the process have to wait for some I/O,file etc. It
is put in the waiting queue.When the CPU is available it is
again put in running state
TERMINATED-when the process finishes execution.
start ready running terminated
wait
11. • PCB-process control block.
It is the datastructure to manage process
stores unique identification number
current state i.e ready,running
details of subprocesses
access privileges of the process
stores the address of the next instructions
stores information about various cpu registers
Process id
state
Pointer
priority
registers
Program
counter
12. Program execution
1.)Program is loaded into memory
2.)fetch the instructions-CU brings first instruction into
memory
3.)decode the instruction-all the mathematical ,I/O,any logical
work is done.
4.)execute the instruction-ALU carries out the mathematical
work
5.)store the result
6)Fetch the next instruction
13. Process scheduling
When there are a lot of processes in memory ,computer have to
schedule all the jobs to make the efficient utilisation of CPU called
scheduling.
Types of CPU Scheduling-
1.)FCFS-In this the process which arrives first is allocated the cpu first
2.)SJF-CPU picks the next job that will take the shortest time
3.)Round Robin Scheduling-Every process gets fixed equal time to
execute .
MEMORY MANAGEMENT
-keeps track of each and every memory location
-check how much memory is allocated to which process
-decides which process will get memory
-keeps track of the memory that becomes free
14. Memory allocation schemes
1)Single memory allocation-single running app.
Gets the hold of memory
2.)Partitioned-Primary memory is partitioned,and
the running process is allocated one partition
3.Paged memory allocation-memory is divided into
fixed sized units called pages.process is loaded
into pages
4.)Segmented memory allocation-memory is
divided logically into fixed segments .They may
not be contigous.
15. I/O management
• The role of i/O manager of OS is to connect
the process to actual I/O device through some
stratergy.
• The I/O manager sends the request to physical
device and upon receiving response ,it passes
it to the process
Thanking You
Shaifali saini
PGT(CS)