0% found this document useful (0 votes)
22 views31 pages

AOS1PPT

AOs slides

Uploaded by

NarasimY
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views31 pages

AOS1PPT

AOs slides

Uploaded by

NarasimY
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Advanced Operating Systems

Advanced Operating Systems


Session 1

Yayati Gupta
[email protected]

Mahindra University

December 10, 2024

Yayati Gupta (Mahindra University) Advanced Operating Systems December 10, 2024 1 / 23
Advanced Operating Systems

Outline

1 Introduction

2 OS: A brief motivation

3 Virtualisation
CPU Virtualisation
The proc filesystem
Memory Virtualisation

4 Multithreading

Yayati Gupta (Mahindra University) Advanced Operating Systems December 10, 2024 2 / 23
Introduction
Advanced Operating Systems
Introduction

About the Instructor

Yayati Gupta (Mahindra University) Advanced Operating Systems December 10, 2024 4 / 23
Advanced Operating Systems
Introduction

About the Course

1 OS Refresher
2 Prerequisite: C/C++ (Pointers, dynamic memory allocation, file handling), Shell
commands
First assignment due next week
3 Use Linux: Install virtual box/ WSL (Installing Virtual Machine and Shell Commands)

Yayati Gupta (Mahindra University) Advanced Operating Systems December 10, 2024 5 / 23
Advanced Operating Systems
Introduction

About the Course

1 OS Refresher
2 Prerequisite: C/C++ (Pointers, dynamic memory allocation, file handling), Shell
commands
First assignment due next week
3 Use Linux: Install virtual box/ WSL (Installing Virtual Machine and Shell Commands)

Yayati Gupta (Mahindra University) Advanced Operating Systems December 10, 2024 5 / 23
Advanced Operating Systems
Introduction

About the Course

1 OS Refresher
2 Prerequisite: C/C++ (Pointers, dynamic memory allocation, file handling), Shell
commands
First assignment due next week
3 Use Linux: Install virtual box/ WSL (Installing Virtual Machine and Shell Commands)

Yayati Gupta (Mahindra University) Advanced Operating Systems December 10, 2024 5 / 23
Advanced Operating Systems
Introduction

About the Course

1 OS Refresher
2 Prerequisite: C/C++ (Pointers, dynamic memory allocation, file handling), Shell
commands
First assignment due next week
3 Use Linux: Install virtual box/ WSL (Installing Virtual Machine and Shell Commands)

Yayati Gupta (Mahindra University) Advanced Operating Systems December 10, 2024 5 / 23
Advanced Operating Systems
Introduction

About the Course: Agenda

1 A friendly introduction
2 Process management
3 Basic scheduling algorithms
4 More nuanced algorithms
Linux’s fair share scheduling algorithms
Real time scheduling algorithms
Multicore heterogenous scheduling algorithms
5 Threads and semaphores
6 Memory Management

Yayati Gupta (Mahindra University) Advanced Operating Systems December 10, 2024 6 / 23
OS: A brief motivation
Advanced Operating Systems
OS: A brief motivation

OS: Not just an abstraction

Yayati Gupta (Mahindra University) Advanced Operating Systems December 10, 2024 8 / 23
Advanced Operating Systems
OS: A brief motivation

The roles of OS
1 Process management
2 memory management
3 file system management
4 device management
5 security and access control
6 user interface management
7 multitasking and multithreading
8 error detection and handling
9 networking and communication
10 resource allocation
11 system performance monitoring
Yayati Gupta (Mahindra University) Advanced Operating Systems December 10, 2024 9 / 23
Virtualisation
Advanced Operating Systems
Virtualisation
CPU Virtualisation

CPU Virtualisation

# include < stdio .h >


# include < unistd .h > // For usleep

int main ( int argc , char * argv []) {


char * x = argv [1];
for ( int i = 0; i < 10; i ++) {
printf ( " % s \ n " , x );
usleep (500000); // 500 ,000 microseconds = 0.5 seconds
}
return 0;
}

Yayati Gupta (Mahindra University) Advanced Operating Systems December 10, 2024 11 / 23
Advanced Operating Systems
Virtualisation
CPU Virtualisation

CPU Virtualisation (contd.)


//Shell commands to run
gcc cpu.c -o CPU
./cpu A & ./cpu B & ./cpu C & ./cpu D
Note your output here

How are 4 programs running at once?


Will the output order be same everytime?
Yayati Gupta (Mahindra University) Advanced Operating Systems December 10, 2024 12 / 23
Advanced Operating Systems
Virtualisation
CPU Virtualisation

CPU Virtualisation (contd.)


A slight modification

Modify the code to include the core number on which each process is runninga . What
are your observations?

a
Refer to cpu core.c in the code folder of the course

Yayati Gupta (Mahindra University) Advanced Operating Systems December 10, 2024 13 / 23
Advanced Operating Systems
Virtualisation
CPU Virtualisation

/proc Filesystem

1 VFS created dynamically during booting


2 Kernel information
/proc/cpuinfo
/proc/meminfo
3 Process information
4 System tools configuration like ‘top’ and ‘ps’

Yayati Gupta (Mahindra University) Advanced Operating Systems December 10, 2024 14 / 23
Advanced Operating Systems
Virtualisation
CPU Virtualisation

/proc Filesystem

1 VFS created dynamically during booting


2 Kernel information
/proc/cpuinfo
/proc/meminfo
3 Process information
4 System tools configuration like ‘top’ and ‘ps’

Yayati Gupta (Mahindra University) Advanced Operating Systems December 10, 2024 14 / 23
Advanced Operating Systems
Virtualisation
CPU Virtualisation

/proc Filesystem

1 VFS created dynamically during booting


2 Kernel information
/proc/cpuinfo
/proc/meminfo
3 Process information
4 System tools configuration like ‘top’ and ‘ps’

Yayati Gupta (Mahindra University) Advanced Operating Systems December 10, 2024 14 / 23
Advanced Operating Systems
Virtualisation
CPU Virtualisation

/proc Filesystem

1 VFS created dynamically during booting


2 Kernel information
/proc/cpuinfo
/proc/meminfo
3 Process information
4 System tools configuration like ‘top’ and ‘ps’

Yayati Gupta (Mahindra University) Advanced Operating Systems December 10, 2024 14 / 23
Advanced Operating Systems
Virtualisation
CPU Virtualisation

/proc Filesystem

1 VFS created dynamically during booting


2 Kernel information
/proc/cpuinfo
/proc/meminfo
3 Process information
4 System tools configuration like ‘top’ and ‘ps’

Yayati Gupta (Mahindra University) Advanced Operating Systems December 10, 2024 14 / 23
Advanced Operating Systems
Virtualisation
CPU Virtualisation

/proc Filesystem

1 VFS created dynamically during booting


2 Kernel information
/proc/cpuinfo
/proc/meminfo
3 Process information
4 System tools configuration like ‘top’ and ‘ps’

Yayati Gupta (Mahindra University) Advanced Operating Systems December 10, 2024 14 / 23
Advanced Operating Systems
Virtualisation
CPU Virtualisation

/proc Filesystem: Assignment 1

1 Link: Assignment 1
2 Pre-requisites
Understanding the /proc FS and its structure
Basic Linux commands like cd, ls, cat and man
C/C++ Programming, ability to read and parse files with file handling functions like fgets()
and fscanf()
Exploration and creativity

Yayati Gupta (Mahindra University) Advanced Operating Systems December 10, 2024 15 / 23
Advanced Operating Systems
Virtualisation
Memory Virtualisation

Memory Virtualisation

# include < stdio .h >


# include < stdlib .h >
int main ( int num , char * vals [])
{
int * p = ( int *) malloc ( sizeof ( int ));
int p_val = atoi ( vals [1]);
printf ( " \ np = %p ,\ n val = % d \ n " ,p , p_val );
return (0);
}

Yayati Gupta (Mahindra University) Advanced Operating Systems December 10, 2024 16 / 23
Advanced Operating Systems
Virtualisation
Memory Virtualisation

Memory Virtualisation
//Disable address space layout randomisation (ASLR)
echo 0 | sudo tee /proc/sys/kernel/randomize_va_space

Value Randomisation Level


0 No randomisation
1 Partial randomisation (eg stack)
2 Full randomisation

//Run the code


gcc mem.c -o mem
./mem 3 & ./mem 4
Yayati Gupta (Mahindra University) Advanced Operating Systems December 10, 2024 17 / 23
Advanced Operating Systems
Virtualisation
Memory Virtualisation

Memory Virtualisation

Notice how both variables have the same address. Does this mean memory sharing is
occurring between the two processes?

Yayati Gupta (Mahindra University) Advanced Operating Systems December 10, 2024 18 / 23
Advanced Operating Systems
Virtualisation
Memory Virtualisation

Memory Virtualisation

Notice how both variables have the same address. Does this mean memory sharing is
occurring between the two processes?

Imagine this: You’ve just bought the latest, most epic video game, SpaceQuest 3000,
and you’re ready to dive into hours of intergalactic fun. You eagerly install it, but there’s
a problem. The game’s file size is a whopping 8 GB, but your computer’s RAM can only
handle 4 GB at once. Uh-oh! Will you be able to play it?

Yayati Gupta (Mahindra University) Advanced Operating Systems December 10, 2024 19 / 23
Multithreading
Advanced Operating Systems
Multithreading

Multithreading: An Unsynchronised Example


int marks = 70;
int loops ;
void * adam ( void * arg ) {
int i ;
for ( i = 0; i < loops ; i ++) marks ++;
}
void * eve ( void * arg ) {
int i ;
for ( i = 0; i < loops ; i ++) marks - -;
}
// Main : Runs both threads simultaneously
}

See the complete code here.


Yayati Gupta (Mahindra University) Advanced Operating Systems December 10, 2024 21 / 23
Advanced Operating Systems
Multithreading

Multithreading (contd..)

What happens as you increase the number of loops and why?

Figure: Northeast Blackout (2003), Therac-25 (1985), Toyota Unintended Acceleration (2005)
Yayati Gupta (Mahindra University) Advanced Operating Systems December 10, 2024 22 / 23
Advanced Operating Systems
Multithreading

Thank You

Questions?

Yayati Gupta (Mahindra University) Advanced Operating Systems December 10, 2024 23 / 23

You might also like