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

Post on 21-Jan-2016

217 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

Transcript

1

Unix

Architecture

2

Operating Systems Concepts

1. Process

2. Memory management

3. Information protection & security

4. Scheduling and resource management

5. The Shell

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.

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

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.

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

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.

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.

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.

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.

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

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

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.

14

Solaris 2 Threads

15

Interprocess Communication (IPC)

I/O Pipes Shared memory Message Passing

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

17

Pipes

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

write) Pipe types:

• Named pipe

• Unnamed pipes

18

The File System

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.

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

21

In-Memory File System Structures

22

Indexed Allocation

Brings all pointers together into the index block.

index table

23

Example of Indexed Allocation

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.

25

UNIX inode (UFS)

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

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

28

UNIX

29

UNIX

30

UNIX

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

32

UNIX

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

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

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

36

Traditional UNIX Scheduling (Example)

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

38

Linux Scheduling: FIFO vs. RR

top related