Top Banner
1 Unix Architecture
38

1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

Jan 21, 2016

Download

Documents

Kenneth Cannon
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

1

Unix

Architecture

Page 2: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

2

Operating Systems Concepts

1. Process

2. Memory management

3. Information protection & security

4. Scheduling and resource management

5. The Shell

Page 3: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

3

System Structure – UNIX

UNIX – The kernel• Consists of

everything below the system-call interface and above the physical hardware

• Provides the file system, CPU scheduling, memory management, and other operating-system functions.

Page 4: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

4

Process Concept

Process – a program in execution UNIX’s process definition:

“an address space with one or more threads executing within that address space, and the required system resources for those threads.”

A process includes:• program counter

• stack

• data section

Page 5: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

5

Process State

As a process executes, it changes state• new: The process is being created.

• running: Instructions are being executed.

• waiting: The process is waiting for some event to occur.

• ready: The process is waiting to be assigned to a process.

• terminated: The process has finished execution.

Page 6: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

6

Process Control Block (PCB)

Information associated with each process.• Process state

• Program counter

• CPU registers

• CPU scheduling information

• Memory-management information

• Accounting information

• I/O status information

Page 7: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

7

Context Switch

When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process.

Context-switch time is overhead; the system does no useful work while switching.

Page 8: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

8

Some of the Process Scheduling Queues

Job queue – set of all processes in the system.

Ready queue – set of all processes residing in main memory,ready and waiting to execute.

Device queues – set of processes waiting for an I/O device.

Process migration between the various queues.

Page 9: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

9

Schedulers

Long-term scheduler (or job scheduler) – selects which processes should be brought into the ready queue.

Short-term scheduler (or CPU scheduler) – selects which process should be executed next and allocates CPU.

Page 10: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

10

Process Creation

Parent process creates children processes, which, in turn create other processes, forming a tree of processes.

Execution• Parent and children execute concurrently.

• Parent waits until children terminate.

Page 11: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

11

Signals

A signal is an event generated by the UNIX system in response to some condition:• Errors - memory violations, math processors errors

• Interrupt

• Calling to kill system call

Page 12: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

12

Threads (briefly)

A thread (or lightweight process) is consists of:• program counter

• register set

• stack space

A thread shares with its peer threads its:• code section

• data section

• operating-system resources

A traditional or heavyweight process is equal to a task with one thread

Page 13: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

13

Threads Support in Solaris 2

Solaris 2 is a version of UNIX with support for threads at the kernel and user levels, symmetric multiprocessing, and real-time scheduling.

LWP – intermediate level between user-level threads and kernel-level threads.

Resource needs of thread types:• Kernel thread: small data structure and a stack; thread switching

does not require changing memory access information – relatively fast.

• LWP: PCB with register data, accounting and memory information,; switching between LWPs is relatively slow.

• User-level thread: only need stack and program counter; no kernel involvement means fast switching. Kernel only sees the LWPs that support user-level threads.

Page 14: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

14

Solaris 2 Threads

Page 15: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

15

Interprocess Communication (IPC)

I/O Pipes Shared memory Message Passing

Page 16: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

16

I/O System Calls

I/O operations made by descriptors Descriptors are integer values represent indexes

for special tables that are handle by the OS kernel to access the data – (a file can be a device also)

Every process has his own descriptors , saved in his PDT – process descriptor table

By default , every process has 3 descriptors:• 0 – stdin - keyboard

• 1 – stdout - screen

• 2 – stderr - screen

Page 17: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

17

Pipes

FIFO data passing Can use for synchronization Implement via files by two descriptors (read ,

write) Pipe types:

• Named pipe

• Unnamed pipes

Page 18: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

18

The File System

Page 19: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

19

File Attributes

Name – only information kept in human-readable form.

Type – needed for systems that support different types.

Location – pointer to file location on device. Size – current file size. Protection – controls who can do reading, writing,

executing. Time, date, and user identification – data for

protection, security, and usage monitoring.Information about files are kept in the directory

structure, which is maintained on the disk.

Page 20: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

20

Access Lists and Groups

Mode of access: read, write, execute Three classes of users

RWXa) owner access 7 1 1 1

RWXb) groups access 6 1 1 0

RWXc) public access 1 0 0 1

Attach a group to a file

chgrp G game

owner group public

chmod 761 game

Page 21: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

21

In-Memory File System Structures

Page 22: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

22

Indexed Allocation

Brings all pointers together into the index block.

index table

Page 23: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

23

Example of Indexed Allocation

Page 24: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

24

Indexed Allocation (Cont.)

Need index table Random access have overhead of index block. Mapping from logical to physical in a file of

maximum size of 256K words and block size of 512 words. We need only 1 block for index table.

Page 25: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

25

UNIX inode (UFS)

Page 26: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

26

Disk Partition

Booting the operating system• Primary Boot Sector (sector 0) –

MBR and Partition Table – allocate the active partition and jump to it’s secondary boot sector

• Active Partition – the loader of the OS is in the secondary boot sector – set the OS file system

• inactive partition – the secondary boot sector is ignored – additional file system

Page 27: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

27

Disk Formatting and Partitioning

Disk Partitioning • MS-DOS /Linux – fdisk

• MS-DOS partitions can mount as separate drives

• Linux – one partition for root file system and one for swap file system

Disk Formatting• Setup the partition with the file system structure

• MS-DOS format – bootstrap code, FAT, root directory

• UNIX mkfs – bootstrap code ,super block , i-nodes

Page 28: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

28

UNIX

Page 29: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

29

UNIX

Page 30: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

30

UNIX

Page 31: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

31

UNIX

i-node structure is small , fixed size Smaller files can be accessed quickly –

larger files longer How big can a file be ?

• Assume 1K disk block and 32 bit address

• 10Kb + 256 * 1K + 256*256*1K + 256*256*256*1K > 16GB

Page 32: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

32

UNIX

Page 33: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

33

Traditional UNIX Scheduling

Scheduling algorithm objectives• Provide good response time for interactive users• Ensure that low-priority background jobs do not starve

Scheduling algorithm implementation• Multilevel feedback using round robin within each of the

priority queues• 1 second preemption• Priority based on process type and execution history• Priorities are recomputed once per second• Base priority divides all processes into fixed bands of

priority levels• Bands used to optimize access to block devices (e.g., disk)

and to allow the OS to respond quickly to system calls

Page 34: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

34

Traditional UNIX Scheduling (cont.)

CPU j (i) = Measure of processor utilization by process j through interval i

P j ( i ) = Priority of process j at beginning of interval i ;

lower values equal higher priorities

Base j = Base priority of process j

nice j = User controllable adjustment factor

CPU j ( i – 1)

P j (i) = Base j +

2

CPU j ( i – 1)

2

CPU j (i) =

+ nice j

Page 35: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

35

Traditional UNIX Scheduling (cont.)

Bands in decreasing order of priority• Swapper• Block I/O device control• File manipulation• Character I/O device control• User processes

Goals• Provide the most efficient use of I/O devices• Within the user process band, use the execution history to

penalize processor-bound processes at the expense of I/O bound processes

Example of process scheduling• Processes A, B, and C are created at the same time with base

priorities of 60• Clock interrupts the system 60 times a second and increments

counter for running process

Page 36: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

36

Traditional UNIX Scheduling (Example)

Page 37: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

37

Linux Scheduling

Enhances the traditional UNIX scheduling by adding two new scheduling classes for real-time processing

Scheduling classes• SCHED_FIFO: First-in-first-out real-time threads

• SCHED_RR: Round-robin real-time threads

• SCHED_OTHER: Other, non-real-time threads

Page 38: 1 Unix Architecture. 2 Operating Systems Concepts 1. Process 2. Memory management 3. Information protection & security 4. Scheduling and resource management.

38

Linux Scheduling: FIFO vs. RR