Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir...

91
Introduction to Operating Systems (Part III) Amir H. Payberah [email protected] Amirkabir University of Technology (Tehran Polytechnic) Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 1 / 43

Transcript of Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir...

Page 1: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Introduction to Operating Systems(Part III)

Amir H. [email protected]

Amirkabir University of Technology(Tehran Polytechnic)

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 1 / 43

Page 2: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Operating System Structure

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 2 / 43

Page 3: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Operating System Structure

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 3 / 43

Page 4: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

User Space

I System programs

I Application programs

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 4 / 43

Page 5: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Kernel Space

I Process management

I Memory management

I Storage management and File system

I Device control and I/O subsystem

I Protection and security

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 5 / 43

Page 6: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

System Calls

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 6 / 43

Page 7: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

System Calls

I Programming interface to the services provided by the OS.

I Typically written in a high-level language (C or C++).

I Mostly accessed by programs via a high-level Application Program-ming Interface (API) rather than direct system call use.

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 7 / 43

Page 8: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

System Calls

I Programming interface to the services provided by the OS.

I Typically written in a high-level language (C or C++).

I Mostly accessed by programs via a high-level Application Program-ming Interface (API) rather than direct system call use.

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 7 / 43

Page 9: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

System Calls

I Programming interface to the services provided by the OS.

I Typically written in a high-level language (C or C++).

I Mostly accessed by programs via a high-level Application Program-ming Interface (API) rather than direct system call use.

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 7 / 43

Page 10: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Application Programming Interface (API)

I The API specifies a set of functions that are available to an appli-cation programmer.

• It includes the parameters that are passed to each function and thereturn values the programmer can expect.

I Three most common APIs:

• POSIX API for Unix, Linux, and Mac OS X• Win32 API for Windows• Java API for the Java virtual machine (JVM)

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 8 / 43

Page 11: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Application Programming Interface (API)

I The API specifies a set of functions that are available to an appli-cation programmer.

• It includes the parameters that are passed to each function and thereturn values the programmer can expect.

I Three most common APIs:

• POSIX API for Unix, Linux, and Mac OS X• Win32 API for Windows• Java API for the Java virtual machine (JVM)

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 8 / 43

Page 12: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Application Programming Interface (API)

I The API specifies a set of functions that are available to an appli-cation programmer.

• It includes the parameters that are passed to each function and thereturn values the programmer can expect.

I Three most common APIs:

• POSIX API for Unix, Linux, and Mac OS X• Win32 API for Windows• Java API for the Java virtual machine (JVM)

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 8 / 43

Page 13: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Application Programming Interface (API)

I The API specifies a set of functions that are available to an appli-cation programmer.

• It includes the parameters that are passed to each function and thereturn values the programmer can expect.

I Three most common APIs:• POSIX API for Unix, Linux, and Mac OS X

• Win32 API for Windows• Java API for the Java virtual machine (JVM)

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 8 / 43

Page 14: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Application Programming Interface (API)

I The API specifies a set of functions that are available to an appli-cation programmer.

• It includes the parameters that are passed to each function and thereturn values the programmer can expect.

I Three most common APIs:• POSIX API for Unix, Linux, and Mac OS X• Win32 API for Windows

• Java API for the Java virtual machine (JVM)

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 8 / 43

Page 15: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Application Programming Interface (API)

I The API specifies a set of functions that are available to an appli-cation programmer.

• It includes the parameters that are passed to each function and thereturn values the programmer can expect.

I Three most common APIs:• POSIX API for Unix, Linux, and Mac OS X• Win32 API for Windows• Java API for the Java virtual machine (JVM)

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 8 / 43

Page 16: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Example of Standard API

> man read

READ(2) Linux Programmers Manual READ(2)

NAME

read - read from a file descriptor

SYNOPSIS

#include <unistd.h>

ssize_t read(int fd, void *buf, size_t count);

DESCRIPTION

read() attempts to read up to count bytes from file descriptor fd into the buffer starting

at buf.

If count is zero, read() returns zero and has no other results. If count is greater than

SSIZE_MAX, the result is unspecified.

RETURN VALUE

On success, the number of bytes read is returned (zero indicates end of file), and the

file position is advanced by this number.

...

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 9 / 43

Page 17: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

I Why would an application programmer prefer programming accord-ing to an API rather than invoking actual system calls?

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 10 / 43

Page 18: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

API and System Calls

> cp a.txt b.txt

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 11 / 43

Page 19: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

API and System Calls

> strace cp a.txt b.txt

execve("/bin/cp", ["cp", "a.txt", "b.txt"], [/* 49 vars */]) = 0

brk(0) = 0x8a2d000

access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)

mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb76ff000

access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)

open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3

fstat64(3, {st_mode=S_IFREG|0644, st_size=108563, ...}) = 0

mmap2(NULL, 108563, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb76e4000

close(3) = 0

access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)

open("/lib/i386-linux-gnu/libselinux.so.1", O_RDONLY|O_CLOEXEC) = 3

read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0@A\0\0004\0\0\0"..., 512) = 512

fstat64(3, {st_mode=S_IFREG|0644, st_size=120748, ...}) = 0

mmap2(NULL, 125852, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb76c5000

mmap2(0xb76e2000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1c) = 0xb76e2000

close(3) = 0

access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)

open("/lib/i386-linux-gnu/librt.so.1", O_RDONLY|O_CLOEXEC) = 3

read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\320\30\0\0004\0\0\0"..., 512) = 512

fstat64(3, {st_mode=S_IFREG|0644, st_size=30684, ...}) = 0

mmap2(NULL, 33360, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb76bc000

mmap2(0xb76c3000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x6) = 0xb76c3000

close(3) = 0

...

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 12 / 43

Page 20: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

System Call Interface

I The system call interface intercepts function calls in the API andinvokes the necessary system calls within the OS.

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 13 / 43

Page 21: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

System Calls Implementation (1/2)

I Typically, a number associated with each system call.

I System-call interface maintains a table indexed according to thesenumbers.

I The system call interface invokes the intended system call in OSkernel and returns status of the system call and any return values.

[http://www.rootkitanalytics.com/kernelland]

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 14 / 43

Page 22: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

System Calls Implementation (1/2)

I Typically, a number associated with each system call.

I System-call interface maintains a table indexed according to thesenumbers.

I The system call interface invokes the intended system call in OSkernel and returns status of the system call and any return values.

[http://www.rootkitanalytics.com/kernelland]

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 14 / 43

Page 23: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

System Calls Implementation (1/2)

I Typically, a number associated with each system call.

I System-call interface maintains a table indexed according to thesenumbers.

I The system call interface invokes the intended system call in OSkernel and returns status of the system call and any return values.

[http://www.rootkitanalytics.com/kernelland]

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 14 / 43

Page 24: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

System Calls Implementation (2/2)

I The caller does not need to know about the system call implemen-tation.

I Just needs to obey API and understand what OS will do as a resultcall.

I Most details of OS interface hidden from programmer by API.

[http://www.rootkitanalytics.com/kernelland]

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 15 / 43

Page 25: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

System Calls Implementation (2/2)

I The caller does not need to know about the system call implemen-tation.

I Just needs to obey API and understand what OS will do as a resultcall.

I Most details of OS interface hidden from programmer by API.

[http://www.rootkitanalytics.com/kernelland]

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 15 / 43

Page 26: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

System Calls Implementation (2/2)

I The caller does not need to know about the system call implemen-tation.

I Just needs to obey API and understand what OS will do as a resultcall.

I Most details of OS interface hidden from programmer by API.

[http://www.rootkitanalytics.com/kernelland]

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 15 / 43

Page 27: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

System Call Parameter Passing (1/2)

I Three general methods used to pass parameters to the OS.

1 Pass the parameters in registers.• In some cases, may be more parameters than registers.

2 Parameters stored in a block or table, in memory, and address ofblock passed as a parameter in a register.

3 Parameters pushed onto the stack by the program and popped offthe stack by the OS.

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 16 / 43

Page 28: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

System Call Parameter Passing (1/2)

I Three general methods used to pass parameters to the OS.

1 Pass the parameters in registers.• In some cases, may be more parameters than registers.

2 Parameters stored in a block or table, in memory, and address ofblock passed as a parameter in a register.

3 Parameters pushed onto the stack by the program and popped offthe stack by the OS.

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 16 / 43

Page 29: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

System Call Parameter Passing (1/2)

I Three general methods used to pass parameters to the OS.

1 Pass the parameters in registers.• In some cases, may be more parameters than registers.

2 Parameters stored in a block or table, in memory, and address ofblock passed as a parameter in a register.

3 Parameters pushed onto the stack by the program and popped offthe stack by the OS.

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 16 / 43

Page 30: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

System Call Parameter Passing (1/2)

I Three general methods used to pass parameters to the OS.

1 Pass the parameters in registers.• In some cases, may be more parameters than registers.

2 Parameters stored in a block or table, in memory, and address ofblock passed as a parameter in a register.

3 Parameters pushed onto the stack by the program and popped offthe stack by the OS.

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 16 / 43

Page 31: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

System Call Parameter Passing (2/2)

[Passing of parameters as a table]

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 17 / 43

Page 32: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Types of System Calls

I System calls can be grouped roughly into six major categories:

1 Process control

2 File manipulation

3 Device manipulation

4 Information maintenance

5 Communications

6 Protection

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 18 / 43

Page 33: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Process Control System Calls

I create process, terminate process

I end, abort

I load, execute

I get process attributes, set process attributes

I wait for time

I wait event, signal event

I allocate and free memory

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 19 / 43

Page 34: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Process Control System Calls

I create process, terminate process

I end, abort

I load, execute

I get process attributes, set process attributes

I wait for time

I wait event, signal event

I allocate and free memory

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 19 / 43

Page 35: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Process Control System Calls

I create process, terminate process

I end, abort

I load, execute

I get process attributes, set process attributes

I wait for time

I wait event, signal event

I allocate and free memory

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 19 / 43

Page 36: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Process Control System Calls

I create process, terminate process

I end, abort

I load, execute

I get process attributes, set process attributes

I wait for time

I wait event, signal event

I allocate and free memory

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 19 / 43

Page 37: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Process Control System Calls

I create process, terminate process

I end, abort

I load, execute

I get process attributes, set process attributes

I wait for time

I wait event, signal event

I allocate and free memory

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 19 / 43

Page 38: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Process Control System Calls

I create process, terminate process

I end, abort

I load, execute

I get process attributes, set process attributes

I wait for time

I wait event, signal event

I allocate and free memory

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 19 / 43

Page 39: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Process Control System Calls

I create process, terminate process

I end, abort

I load, execute

I get process attributes, set process attributes

I wait for time

I wait event, signal event

I allocate and free memory

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 19 / 43

Page 40: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

File Management System Calls

I create file, delete file

I open, close

I read, write, reposition

I get file attributes, set file attributes

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 20 / 43

Page 41: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

File Management System Calls

I create file, delete file

I open, close

I read, write, reposition

I get file attributes, set file attributes

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 20 / 43

Page 42: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

File Management System Calls

I create file, delete file

I open, close

I read, write, reposition

I get file attributes, set file attributes

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 20 / 43

Page 43: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

File Management System Calls

I create file, delete file

I open, close

I read, write, reposition

I get file attributes, set file attributes

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 20 / 43

Page 44: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Device Management System Calls

I request device, release device

I read, write, reposition

I get device attributes, set device attributes

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 21 / 43

Page 45: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Device Management System Calls

I request device, release device

I read, write, reposition

I get device attributes, set device attributes

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 21 / 43

Page 46: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Device Management System Calls

I request device, release device

I read, write, reposition

I get device attributes, set device attributes

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 21 / 43

Page 47: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Information Management System Calls

I get/set time or date

I get/set system data

I get/set process, file, or device attributes

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 22 / 43

Page 48: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Information Management System Calls

I get/set time or date

I get/set system data

I get/set process, file, or device attributes

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 22 / 43

Page 49: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Information Management System Calls

I get/set time or date

I get/set system data

I get/set process, file, or device attributes

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 22 / 43

Page 50: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Communications System Calls

I create, delete communication connection

I send, receive messages

I transfer status information

I attach or detach remote devices

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 23 / 43

Page 51: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Communications System Calls

I create, delete communication connection

I send, receive messages

I transfer status information

I attach or detach remote devices

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 23 / 43

Page 52: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Communications System Calls

I create, delete communication connection

I send, receive messages

I transfer status information

I attach or detach remote devices

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 23 / 43

Page 53: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Communications System Calls

I create, delete communication connection

I send, receive messages

I transfer status information

I attach or detach remote devices

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 23 / 43

Page 54: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Operating System Architecture

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 24 / 43

Page 55: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Operating System Architecture (1/2)

I General-purpose OS is very large program.

I A common approach is to partition the task into small components,rather than have one monolithic system.

I Each component should be a well-defined portion of the system,with carefully defined inputs, outputs, and functions.

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 25 / 43

Page 56: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Operating System Architecture (1/2)

I General-purpose OS is very large program.

I A common approach is to partition the task into small components,rather than have one monolithic system.

I Each component should be a well-defined portion of the system,with carefully defined inputs, outputs, and functions.

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 25 / 43

Page 57: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Operating System Architecture (1/2)

I General-purpose OS is very large program.

I A common approach is to partition the task into small components,rather than have one monolithic system.

I Each component should be a well-defined portion of the system,with carefully defined inputs, outputs, and functions.

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 25 / 43

Page 58: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Operating System Architecture (2/2)

I Various ways to structure ones:• Simple structure, e.g., MS-DOS• More complex structure, e.g., Unix• Layered, an abstraction• Microkernel, e.g., Mach

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 26 / 43

Page 59: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Simple Structure

I Provide the most functionality in the least space.

I Not divided into modules.

I Its interfaces and levels of functionalityare not well separated.

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 27 / 43

Page 60: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

More Complex Structure (1/2)

I the original Unix had limited structuring.

I The Unix consists of two separable parts:

1 Systems programs

2 The kernel

• Everything below the system call interface and above the hardware.

• Provides the file system, CPU scheduling, memory management,and other operating-system functions; a large number of functionsfor one level.

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 28 / 43

Page 61: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

More Complex Structure (1/2)

I the original Unix had limited structuring.

I The Unix consists of two separable parts:

1 Systems programs

2 The kernel

• Everything below the system call interface and above the hardware.

• Provides the file system, CPU scheduling, memory management,and other operating-system functions; a large number of functionsfor one level.

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 28 / 43

Page 62: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

More Complex Structure (1/2)

I the original Unix had limited structuring.

I The Unix consists of two separable parts:

1 Systems programs

2 The kernel

• Everything below the system call interface and above the hardware.

• Provides the file system, CPU scheduling, memory management,and other operating-system functions; a large number of functionsfor one level.

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 28 / 43

Page 63: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

More Complex Structure (1/2)

I the original Unix had limited structuring.

I The Unix consists of two separable parts:

1 Systems programs

2 The kernel

• Everything below the system call interface and above the hardware.

• Provides the file system, CPU scheduling, memory management,and other operating-system functions; a large number of functionsfor one level.

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 28 / 43

Page 64: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

More Complex Structure (2/2)

[Traditional Unix system structure]

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 29 / 43

Page 65: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Layered Structure

I The operating system is divided into a number of layers.

I Each layer is built on top of lower layers.

I The bottom layer is the hardware.

I The highest layer is the user interface.

I Layers are selected such that each uses functions and services ofonly lower-level layers.

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 30 / 43

Page 66: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Layered Structure

I The operating system is divided into a number of layers.

I Each layer is built on top of lower layers.

I The bottom layer is the hardware.

I The highest layer is the user interface.

I Layers are selected such that each uses functions and services ofonly lower-level layers.

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 30 / 43

Page 67: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Layered Structure

I The operating system is divided into a number of layers.

I Each layer is built on top of lower layers.

I The bottom layer is the hardware.

I The highest layer is the user interface.

I Layers are selected such that each uses functions and services ofonly lower-level layers.

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 30 / 43

Page 68: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Layered Structure

I The operating system is divided into a number of layers.

I Each layer is built on top of lower layers.

I The bottom layer is the hardware.

I The highest layer is the user interface.

I Layers are selected such that each uses functions and services ofonly lower-level layers.

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 30 / 43

Page 69: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Microkernel Structure (1/2)

I Moves as much from the kernel into user space.

I Communication takes place between user modules using messagepassing.

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 31 / 43

Page 70: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Microkernel Structure (2/2)

I Advantages:• Easier to extend a microkernel.• Easier to port the OS to new architectures.• More reliable (less code is running in kernel mode).• More secure.

I Disadvantages:• Performance overhead of user space to kernel space communication.

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 32 / 43

Page 71: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Microkernel Structure (2/2)

I Advantages:• Easier to extend a microkernel.• Easier to port the OS to new architectures.• More reliable (less code is running in kernel mode).• More secure.

I Disadvantages:• Performance overhead of user space to kernel space communication.

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 32 / 43

Page 72: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Modules

I Many modern operating systems implement loadable kernel mod-ules.

• Uses object-oriented approach.• Each core component is separate.• Each talks to the others over known interfaces.• Each is loadable as needed within the kernel.

I Overall, similar to layers but with more flexible.• Linux, Solaris, ...

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 33 / 43

Page 73: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Modules

I Many modern operating systems implement loadable kernel mod-ules.

• Uses object-oriented approach.• Each core component is separate.• Each talks to the others over known interfaces.• Each is loadable as needed within the kernel.

I Overall, similar to layers but with more flexible.• Linux, Solaris, ...

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 33 / 43

Page 74: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Hybrid Systems

I Most modern operating systems are actually not one pure model.

I Hybrid combines multiple approaches to address performance, secu-rity, usability needs.

I Linux and Solaris are monolithic, plus modular for dynamic loadingof functionality.

I Windows mostly monolithic, plus microkernel for different subsystempersonalities.

I Apple Mac OS X kernel consists of Mach microkernel and BSD Unixparts, plus I/O kit and dynamically loadable modules

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 34 / 43

Page 75: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Hybrid Systems

I Most modern operating systems are actually not one pure model.

I Hybrid combines multiple approaches to address performance, secu-rity, usability needs.

I Linux and Solaris are monolithic, plus modular for dynamic loadingof functionality.

I Windows mostly monolithic, plus microkernel for different subsystempersonalities.

I Apple Mac OS X kernel consists of Mach microkernel and BSD Unixparts, plus I/O kit and dynamically loadable modules

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 34 / 43

Page 76: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Hybrid Systems

I Most modern operating systems are actually not one pure model.

I Hybrid combines multiple approaches to address performance, secu-rity, usability needs.

I Linux and Solaris are monolithic, plus modular for dynamic loadingof functionality.

I Windows mostly monolithic, plus microkernel for different subsystempersonalities.

I Apple Mac OS X kernel consists of Mach microkernel and BSD Unixparts, plus I/O kit and dynamically loadable modules

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 34 / 43

Page 77: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Hybrid Systems

I Most modern operating systems are actually not one pure model.

I Hybrid combines multiple approaches to address performance, secu-rity, usability needs.

I Linux and Solaris are monolithic, plus modular for dynamic loadingof functionality.

I Windows mostly monolithic, plus microkernel for different subsystempersonalities.

I Apple Mac OS X kernel consists of Mach microkernel and BSD Unixparts, plus I/O kit and dynamically loadable modules

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 34 / 43

Page 78: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Operating SystemDesign and Implementation

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 35 / 43

Page 79: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Operating System Design Goals

I The first problem in designing a system is to define goals and spec-ifications.

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 36 / 43

Page 80: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Operating System Design

I The design of the system will be affected by the choice of hardwareand the type of system:

• batch

• time sharing

• single user/multiuser

• distributed

• real time

• ...

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 37 / 43

Page 81: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Users Goals vs. System Goals

I User goals: OS should be convenient to use, easy to learn, reliable,safe, and fast.

I System goals: OS should be easy to design, implement, and main-tain, as well as flexible, reliable, error-free, and efficient.

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 38 / 43

Page 82: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

How vs. What

I Separating policy from mechanism:• Policy: what to do?• Mechanism: how to do?

I Mechanisms determine how to do something, policies decide whatwill be done.

I The separation of policy from mechanism allows maximum flexibilityif policy decisions are to be changed later.

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 39 / 43

Page 83: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

How vs. What

I Separating policy from mechanism:• Policy: what to do?• Mechanism: how to do?

I Mechanisms determine how to do something, policies decide whatwill be done.

I The separation of policy from mechanism allows maximum flexibilityif policy decisions are to be changed later.

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 39 / 43

Page 84: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

How vs. What

I Separating policy from mechanism:• Policy: what to do?• Mechanism: how to do?

I Mechanisms determine how to do something, policies decide whatwill be done.

I The separation of policy from mechanism allows maximum flexibilityif policy decisions are to be changed later.

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 39 / 43

Page 85: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Implementation

I Early OSes in assembly language.

I Then system programming languages like Algol, PL/1.

I Now C and C++.

I Actually usually a mix of languages:• Lowest levels in assembly.• Main body in C.• Systems programs in C, C++, scripting languages, e.g., Python.

I More high-level language easier to port to other hardware, butslower.

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 40 / 43

Page 86: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Implementation

I Early OSes in assembly language.

I Then system programming languages like Algol, PL/1.

I Now C and C++.

I Actually usually a mix of languages:• Lowest levels in assembly.• Main body in C.• Systems programs in C, C++, scripting languages, e.g., Python.

I More high-level language easier to port to other hardware, butslower.

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 40 / 43

Page 87: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Summary

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 41 / 43

Page 88: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Summary

I Operating-system structure: user-space, system calls, kernel-space

I System calls:• File manipulation• Device manipulation• Information maintenance• Communications• Protection

I Operating-system architecture: simple, layered, micro-kernel, hybrid

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 42 / 43

Page 89: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Summary

I Operating-system structure: user-space, system calls, kernel-space

I System calls:• File manipulation• Device manipulation• Information maintenance• Communications• Protection

I Operating-system architecture: simple, layered, micro-kernel, hybrid

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 42 / 43

Page 90: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Summary

I Operating-system structure: user-space, system calls, kernel-space

I System calls:• File manipulation• Device manipulation• Information maintenance• Communications• Protection

I Operating-system architecture: simple, layered, micro-kernel, hybrid

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 42 / 43

Page 91: Introduction to Operating Systems (Part III) · Introduction to Operating Systems (Part III) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic)

Questions?

Amir H. Payberah (Tehran Polytechnic) Introduction 1393/6/29 43 / 43