Transcript UNIX Arch

Unix
Architecture
1
Operating Systems Concepts
1.
2.
3.
4.
5.
Process
Memory management
Information protection & security
Scheduling and resource management
The Shell
2
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 operatingsystem functions.
3
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
4
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.
5
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
6
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.
7
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.

8
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.
9
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.
10
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
11
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
12
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.
13
Solaris 2 Threads
14
Interprocess Communication (IPC)




I/O
Pipes
Shared memory
Message Passing
15
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
16
Pipes




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
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.

19
Access Lists and Groups



Mode of access: read, write, execute owner
Three classes of users
RWX
chmod
a) owner access 7

111
RWX
b) groups access 6

110
RWX
c) public access
1

001
group
761
public
game
Attach a group to a file
chgrp G game
20
In-Memory File System Structures
21
Indexed Allocation

Brings all pointers together into the index
block.
index table
22
Example of Indexed Allocation
23
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.
24
UNIX inode (UFS)
25
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
26
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
27
UNIX
28
UNIX
29
UNIX
30
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
31
UNIX
32
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
33
Traditional UNIX Scheduling (cont.)
CPU j ( i – 1)
CPU j (i) =
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.)



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
35
Traditional UNIX Scheduling (Example)
36
Linux Scheduling


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