the operating systemlblopes/aulas/ic/t11.pdf · on the pdp-7, in 1969, a team of bell labs...

50
THE OPERATING SYSTEM

Upload: others

Post on 13-Mar-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

THE OPERATING SYSTEM

Page 2: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical
Page 3: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical
Page 4: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical
Page 5: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical
Page 6: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical file system, the concepts of computer processes and device files, a command-line interpreter, and some small utility programs. The resulting system […] was to become

Unix.

(source: Wikipedia)

Page 7: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical
Page 8: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical
Page 9: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

UNIX features and capabilities

• centralised kernel manages resources and processes

• multitasking and multiuser

• programming interface (libraries and shell)

• hierarchical file system

• everything is a file

• built-in networking

• persistent system services called "daemons"

Page 10: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

UNIXINTERNALSTRUCTURE

Page 11: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical
Page 12: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

• process scheduling: which process has access to the CPU? when does it halt? which comes next?

• memory management: can a process be allocated in main memory? if so, where?

• file system: access to files translated into I/O requests for devices.

• device control: load/store data from/to devices to/from memory.

typical kernel functions

Page 13: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

how is the OS kernel loaded into memory?

Page 14: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical
Page 15: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

BIOS (BASIC I/O SYSTEM)

Page 16: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical
Page 17: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

complete boot process (Linux)

Page 18: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

Process Management

Page 19: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

Process Control Block (PCB)

• one per process• holds fundamental information about a process• required to stop it and to make it run again• information includes:

1. process state (e.g., running, suspended)2. process ID3. program counter4. contents of registers5. location of address space6. ID of open files7. and more…

• updated when process (re)starts & when it stops

Page 20: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical
Page 21: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

Process Queues

• the operating system has several process queues

• each queue has PCBs for processes

• typically there is a ready queue

• one queue per each I/O device that processes may be waiting on

Page 22: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

operating systemprocessqueues

inmemory

Page 23: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

• each process is assigned a time quantum• a process runs when it is taken from the front of the ready

queue• something happens when:

1. its quantum ends (moves to end of ready queue)2. it needs to perform I/O (moves to end of a device

queue)3. it forks a child (child moves to end of ready queue)4. it waits for an interrupt (moves to end of device

queue)• PCB is removed from queues when process exits

Process PCBs move between queues

Page 24: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

The Process Cycle

Page 25: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

Process Context Switch

Page 26: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

File System

Page 27: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

In a UNIX system the “file” is the basic unit of data storage

Everything is a file, including peripheral components

The file system is the way UNIX organizes files in mass storage devices such as disks

File systems are kept in sections of disks called partitions that have been previously prepared to hold them (formatted)

Creating such partitions is one of the operations that must be performed in preparation for the installation of an

operating system and its file systems

What is a file system?

Page 28: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

The Unix file system is hierarchical

Page 29: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical
Page 30: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

Memory Management

Page 31: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

the basic execution unit of a UNIX operating system is the process

a binary executable file becomes a process when it is loaded by the operating system loader into memory

the loader assigns it an exclusive address space and copies part of it into main memory

Page 32: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical
Page 33: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

at any time a UNIX operating system may have many processes in the ready or device queues

part of the code and data for these processes must be available in the main memory of the computer

since the size of the main memory is much smaller than the size of the storage devices (usually HDD or SSD with hundreds of MB or a few TB) it follows that only part of

the total information is at any time in memory

Page 34: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

to keep all the processes running it is often required that some space is freed in memory by temporarily removing data from one process to be filled by data from another

this operation involves the transfer of information between memory and disks and is called swapping

Page 35: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

to be able to do this, the operating system must implement a memory management system that keeps track of which processes have information in memory

for any given process only a small part of its address space will be in the main memory at any given time

Page 36: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

more information from the process is transferred from the disks to the main memory as it is required (e.g., a jump to a function whose code is not in memory yet)

when information is requested, during the execution of a process, that is not currently in the main memory, the operating system must provide it, eventually swapping

some information out

Page 37: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

one of the memory management techniques used is called virtual memory and allows the execution of processes whose code/data segments are greater than the physical

limits of main memory

the two main flavours of virtual memory are called pagination and segmentation

Page 38: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

Interrupts

Page 39: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

the cpu die is packaged within a protective plastic/ceramic cocoon and communicates with motherboard through pins

Page 40: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

the cpu die is connected to pins through internal wiring (here Intel 80486)

Page 41: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

the microprocessor exchanges data with the outside and is fed energy through these pins

the microprocessor is interrupted some times, in response to external events, namely:

• timer alarms (e.g., context switch)• input/output requests from devices• hardware or power failures

interrupts have associated (integer) identifiers that identify the type of event

they signal

Page 42: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

interrupt - an unexpected change in control flow in a program that happens independently of the program being executed, e.g., I/O requests, memory errors, power supply failure

Page 43: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

I/O and Device Control

Page 44: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

devices are represented as files in /dev

access to these files triggers special low-level programs called device drivers that allow the operating system to setup and execute I/O operations on the device

there are several types of devices:character — e.g., /dev/tty — teclado, rato, displays

bulk — e.g., /dev/disk0 — HDD, SSD, DVDnetwork — placa de rede

pseudo devices — /dev/null

Page 45: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

data in block devices is often organized into filesystems, of which there are many kinds:

ufs2 — Unix File Systemext2,ext3, ext4 - Extended File System

reiserfs - Reiser File Systemjfs — Journaled File Systemzfs — Zettabyte File System

these differ in features like: the maximum size of the filesystem, support for journaling, support for

compression and data protection

Page 46: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

I/O devices have hardware circuitry called controllers that allow the operating system to control them by issuing low level commands

Page 47: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

an SSD inside with the Flash memory modules and the controller hardware (left)

Page 48: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

the device drivers provide an API to the operating system to control the device and

perform I/O operations

Page 49: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical
Page 50: THE OPERATING SYSTEMlblopes/aulas/ic/T11.pdf · On the PDP-7, in 1969, a team of Bell Labs researchers led by [Ken] Thompson and [Dennis] Ritchie, […], developed a hierarchical

I/O requests involve transfer of data from devices to/from main memory signalled by interrupts

on receiving an interrupt, the CPU stops, calls the corresponding handler that initiates the I/O and

transfers control to the device controller

the CPU returns immediately from the handler and continues with the interrupted process (or suspends

it if the process itself is waiting on the I/O)

when the I/O transfer is complete the controller sends an interrupt to the CPU, acknowledging the

termination or the occurrence of an error