Unix Architecture 1 Operating Systems Concepts 1 2

  • Slides: 38
Download presentation
Unix Architecture 1

Unix Architecture 1

Operating Systems Concepts 1. 2. 3. 4. 5. Process Memory management Information protection &

Operating Systems Concepts 1. 2. 3. 4. 5. Process Memory management Information protection & security Scheduling and resource management The Shell 2

System Structure – UNIX l UNIX – The kernel • Consists of • everything

System Structure – UNIX l 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 operatingsystem functions. 3

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

Process Concept l l l 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 4

Process State l As a process executes, it changes state • • • new:

Process State l 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. 5

Process Control Block (PCB) l Information associated with each process. • • Process state

Process Control Block (PCB) l Information associated with each process. • • Process state Program counter CPU registers CPU scheduling information Memory-management information Accounting information I/O status information 6

Context Switch l l When CPU switches to another process, the system must save

Context Switch l l 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. 7

Some of the Process Scheduling Queues Job queue – set of all processes in

Some of the Process Scheduling Queues Job queue – set of all processes in the system. l Ready queue – set of all processes residing in main memory, ready and waiting to execute. l Device queues – set of processes waiting for an I/O device. Process migration between the various queues. l 8

Schedulers l l Long-term scheduler (or job scheduler) – selects which processes should be

Schedulers l l 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. 9

Process Creation l l Parent process creates children processes, which, in turn create other

Process Creation l l 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. 10

Signals l A signal is an event generated by the UNIX system in response

Signals l 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 11

Threads (briefly) l l l A thread (or lightweight process) is consists of: •

Threads (briefly) l l l 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 12

Threads Support in Solaris 2 l l l Solaris 2 is a version of

Threads Support in Solaris 2 l l l 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. 13

Solaris 2 Threads 14

Solaris 2 Threads 14

Interprocess Communication (IPC) l l I/O Pipes Shared memory Message Passing 15

Interprocess Communication (IPC) l l I/O Pipes Shared memory Message Passing 15

I/O System Calls l l I/O operations made by descriptors Descriptors are integer values

I/O System Calls l l 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 16

Pipes l l FIFO data passing Can use for synchronization Implement via files by

Pipes l l FIFO data passing Can use for synchronization Implement via files by two descriptors (read , write) Pipe types: • Named pipe • Unnamed pipes 17

The File System 18

The File System 18

File Attributes Name – only information kept in human-readable form. l Type – needed

File Attributes Name – only information kept in human-readable form. l Type – needed for systems that support different types. l Location – pointer to file location on device. l Size – current file size. l Protection – controls who can do reading, writing, executing. l 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. l 19

Access Lists and Groups l l l Mode of access: read, write, execute owner

Access Lists and Groups l l l Mode of access: read, write, execute owner group Three classes of users RWX chmod 761 a) owner access 7 111 RWX b) groups access 6 110 RWX c) public access 1 001 Attach a group to a file chgrp G game 20 public game

In-Memory File System Structures 21

In-Memory File System Structures 21

Indexed Allocation l Brings all pointers together into the index block. index table 22

Indexed Allocation l Brings all pointers together into the index block. index table 22

Example of Indexed Allocation 23

Example of Indexed Allocation 23

Indexed Allocation (Cont. ) l l Need index table Random access have overhead of

Indexed Allocation (Cont. ) l l Need index table Random access have overhead of index block. Mapping from logical to physical in a file of maximum size of 256 K words and block size of 512 words. We need only 1 block for index table. 24

UNIX inode (UFS) 25

UNIX inode (UFS) 25

Disk Partition l Booting the operating system • • • Primary Boot Sector (sector

Disk Partition l 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 26

Disk Formatting and Partitioning l Disk Partitioning • MS-DOS /Linux – fdisk • MS-DOS

Disk Formatting and Partitioning l 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 l 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 27

UNIX 28

UNIX 28

UNIX 29

UNIX 29

UNIX 30

UNIX 30

UNIX l l l i-node structure is small , fixed size Smaller files can

UNIX l l l i-node structure is small , fixed size Smaller files can be accessed quickly – larger files longer How big can a file be ? • Assume 1 K disk block and 32 bit address • 10 Kb + 256 * 1 K + 256*256*256*1 K > 16 GB 31

UNIX 32

UNIX 32

Traditional UNIX Scheduling l l Scheduling algorithm objectives • • Provide good response time

Traditional UNIX Scheduling l l Scheduling algorithm objectives • • Provide good response time for interactive users Ensure that low-priority background jobs do not starve • • • 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 Scheduling algorithm implementation 33

Traditional UNIX Scheduling (cont. ) CPU j (i) = CPU j ( i –

Traditional UNIX Scheduling (cont. ) CPU j (i) = CPU j ( i – 1) 2 P j (i) = Base j + CPU j (i) CPU j ( i – 1) + nice j 2 = Measure of processor utilization by process j through Pj(i) = Base j nice j = = Priority of process j at beginning of interval i ; lower values equal higher priorities Base priority of process j User controllable adjustment factor interval i 34

Traditional UNIX Scheduling (cont. ) l l l Bands in decreasing order of priority

Traditional UNIX Scheduling (cont. ) l l l Bands in decreasing order of priority • • • Swapper Block I/O device control File manipulation Character I/O device control User processes • • 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 Goals 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 35

Traditional UNIX Scheduling (Example) 36

Traditional UNIX Scheduling (Example) 36

Linux Scheduling l l Enhances the traditional UNIX scheduling by adding two new scheduling

Linux Scheduling l l Enhances the traditional UNIX scheduling by adding two new scheduling classes for realtime 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 37

Linux Scheduling: FIFO vs. RR 38

Linux Scheduling: FIFO vs. RR 38