UNIX: Background and the Traditional Process and Kernel Abstractions

Lecture 2 Tuesday 28/8/01

Fred Kuhns ( )

CS523S: Operating Systems

A Little History First: UNIX
• Initial design by Ken Thompson, Dennis Ritchie and others at AT&T's Bell Telephone Laboratories (BTL) in 1969: 32 years ago! • AT&T made the source available to Universities for research and educational use. • 1973 UNIX was rewritten in C resulting in Version 4.
The C language was also originally designed and developed for use on the UNIX system by Dennis Ritchie C was evolved from 'B', developed by Thompson.
Fred Kuhns ( ) CS523S: Operating Systems

UNIX History
• AT&T sold UNIX to Novel; Novel passed the UNIX trademark to X/OPEN and sold source code to Santa Cruz Operation (SCO). • Plan 9 is AT&T's successor to UNIX • AT&T was unable to market UNIX as a product so they made the source code available to Universities for use in Research and Education. • Influential variant: Berkeley Software Distributions (BSD) distributed by the Computer Systems Research Group, University of California at Berkeley
 Berkeley obtained UNIX from AT&T in December of 1974
Fred Kuhns ( ) CS523S: Operating Systems

UNIX History
• UNIX ported to many different architectures • Microsoft and SCO collaborated to port UNIX to the Intel 8086 architecture: XENIX • AT&T purchased 20% of Sun: result is joint effort to develop SVR4 • In 1982 AT&T was broken up and was now able to market UNIX. They released System III in 1982 and System V the following year. • System V UNIX introduced virtual memory (different from BSD, called regions), IPC (shared memory, semaphores, message queues), remote file sharing, shared libraries and STREAMS.
Fred Kuhns ( ) CS523S: Operating Systems

BSD UNIX
• • • • • 2 BSD: text editor vi 3 BSD: demand-paged virtual memory 4.0BSD: performance improvements 4.1BSD: job control, autoconfiguration 4.2/4.3BSD: reliable signals, fast filesystem, improved networking (TCP/IP reference implementation), sophisticated IPC primitives • 4.4 BSD: stackable and extensible vnode interface, network filesystem, log-structured filesystem, other filesystems, POSIX support, and other enhancements.
Fred Kuhns ( ) CS523S: Operating Systems

Commercialization
• Interactive Systems first commercial (1977) • Microsoft and SCO release XENIX (1980) • 1982 Bill Joy left Berkeley and founded Sun Microsystems.
 SunOS originall based on BSD 4.2  SunOS 5 (Solaris 2.X) was a collaborative effort based on System V, release 4 (SVR4).

• AIX from IBM • HP/UX from Hewlett Packard Corporation • ULTRIX from Digitial Equipment Corporation, followed by DEC OSF/1. DEC purchased by Compaq
Fred Kuhns ( ) CS523S: Operating Systems

CMU and MACH
• As UNIX grew, the kernel became large and complex originally small and elegant. • Mid-1980 CMU researches began development of a new OS:
 microkernel providing a small set of essential services.  Support UNIX API  Support uniprocessor and multiprocessors  supported distributed environments  collection of servers provide necessary functionality

• New source so not encumbered by AT&T licenses • OSF1 and NextStep based on MACH
Fred Kuhns ( ) CS523S: Operating Systems

Standards
• Problem: Incompatible programming APIs and core service implementations across the different UNIX variants • Solution: Standard set of interfaces. Several standards exist that define the functions, syntax and semantics:
IEEE POSIX (Portable Operating System Interface for computing environments or portable OS for UNIX) specifications. System V Interface Definition (SVID) from AT&T X/Open Portability Guide (XPG) from the X/Open Consortium
Fred Kuhns ( ) CS523S: Operating Systems

Standards
• IEEE POSIX specifications.
 1003.1 (1990) system interfaces and headers  1003.1b (1993) realtime extensions  1003.1c (1995) threads extensions (pthreads)  1003.1 (1996) includes 1003.1 (1990), 1003.1b (1993), 1003.1c (1995), 1003.1i (1995)  1003.1g protocol independent interfaces  1003.2 (1992) Shell and utilities  1003.2a (1992) Interactive shell and utilities

• SVID: SVID4 is for SVR4
 defines the System V programming interface. Must be conformant to call an OS SVR5. AT&T published the System V Verification Suite (SVVS)
Fred Kuhns ( ) CS523S: Operating Systems

Standards
• XPG - formed to develop the Common Applications Environment (CAE).
 XPG3 - Superset of POSIX.1 1998 and utilities from SVID3  XPG4 - Superset of POSIX.1 1990, POSIX.2 (1992), POSIX.2 (1992), and extension from XPG3  XPG4v2 (SUS or single UNIX specification or spc 1170 or UNIX 95) - superset of XPG4 with widely used BSD interfaces  XNS4 (X/Open Network Services) - sockets and XTI extensions  SUSV2 (UNIX98)- superset of SUS, POSIX.1b (1993), POSIX.1c (1996) and ISO/IEC 9899 (C standard). Includes CDE specification  XNS5 - superset of LP64 - clean derivative of XNS4
Fred Kuhns ( ) CS523S: Operating Systems

Traditional Kernel Architecture
execution environment trap user kernel System Services System call interface File subsystem Buffer cache char block Device drivers IPC Process control scheduler subsystem memory application libraries

hardware
Fred Kuhns ( ) CS523S: Operating Systems

Basic Concepts and Terminology
• • • • Two privilege level: user and system each process has own "protected" address space all process share same kernel space kernel space protected: requires special instruction sequence to change from user to kernel mode • per process state (u_area) in kernel space • per process kernel stack; kernel is re-entrant • system (Interrupt) versus process context
Fred Kuhns ( ) CS523S: Operating Systems

Mode, Space and Context
Privileged mode context process system space kernel user kernel

Application System calls (user code) Exceptions X Interrupts not allowed System tasks

UNIX uses only two privilege levels

Fred Kuhns ( )

CS523S: Operating Systems

Overview
• Process
compete for system resources blocks if can not acquire a resource

• Kernel
manages resource - allocate resource to processes "optimally" implements policy for resource allocation (sharing) provide high-level abstract interface to resources centralized management simplifies synchronization and error recovery
Fred Kuhns ( ) CS523S: Operating Systems

The Process
• • • • Fundamental abstraction Executes a sequence of instructions Competes for resources Address space - memory locations accessible to process
virtual address space: memory, disk, swap or remote devices

• System provides features of a virtual machine
shared resources (I/O, CPU etc) dedicated registers and memory
Fred Kuhns ( ) CS523S: Operating Systems

The Process
• Most created by fork or vfork • well defined hierarchy: one parent and zero or more child processes. The init process is at the root of this tree • different programs may be run during the life of a process by calling exec • processes typically terminate by calling exit

Fred Kuhns ( )

CS523S: Operating Systems

Process states
User Running system call, interrupt Zombie wait exit return swtch() Runnable swtch() stop stop Stopped wakeup continue fork fork Initial Idle

Kernel Running

sleep() wakeup Asleep

stop

continue Stopped Asleep
Fred Kuhns ( )

CS523S: Operating Systems

• Address Space

Process Context

text, data, stack, shared memory ...

• Control information (u area, proc)
u area, proc structure, maps kernel stack Address translation maps

• Credentials
user and group ids

• Environment variables
variable=value typically stored at bottom of stack
Fred Kuhns ( ) CS523S: Operating Systems

Process Context (cont)
• Hardware context
program counter stack pointer processor status word memory management registers FPU registers

• Machine registers saved in u area's process control block (PCB) during context switch to another process.
Fred Kuhns ( ) CS523S: Operating Systems

Process Address Space (one approach)
0xffffffff Kernel stack Kernel address space 0x7fffffff stack Process address space Data Text (shared)
CS523S: Operating Systems

0x00000000
Fred Kuhns ( )

Big Picture: Another look
kernel memory proc struct

kernel stack/u area Stack

kernel stack/u area Stack

kernel stack/u area Stack

Data Text (shared)
Fred Kuhns ( )

Data Text (shared)
CS523S: Operating Systems

Data Text (shared)

Process Control Information
• U area.
Part of user space (above stack). typically mapped to a fixed address. contains info needed while running. Can be swapped

• Proc
contains info needed when not running. Not swapped out. traditionally fixed size table
Fred Kuhns ( ) CS523S: Operating Systems

U area and Proc structures
• U Area
 PCB - HW context  pointer to proc  real/effective ids  args, return values or errors to current syscall.  Signal info  file descriptor table  controlling terminal vnode

• Proc structure
 process ID and group  u area pointer  process state  queue pointers - scheduler, sleep, etc.  Priority  memory management info  flags

Fred Kuhns ( )

CS523S: Operating Systems

User Credentials
• Every user is assigned a unique user id (uid) and group id (gid). • Superuser (root) has uid == 0 and gid == 0 • every process both a real and effective pair of Ids.
effective id => file creation and access, real id => real owner of process. Used when sending signals.
Senders real or effective id must equal receivers real id
Fred Kuhns ( ) CS523S: Operating Systems

The Kernel
• program that runs directly on the hardware • loaded at boot time and initializes system,
 creates some initial system processes.  remains in memory and manages the system

• Resource manager/mediator - process is key abstraction.
 Time share (time-slice) the CPU,  coordinate access to peripherals,  manage virtual memory.  Synchronization primitives.

• Well defined entry points:
 syscalls, exceptions or interrupts.

• Performs privileged operations.
Fred Kuhns ( ) CS523S: Operating Systems

Entry into Kernel
• Synchronous - kernel performs work on behalf of the process:
 System call interface (UNIX API): central component of the UNIX API  Hardware exceptions - unusual action of process

• Asynchronous - kernel performs tasks that are possibly unrelated to current process.
 Hardware interrupts - devices assert hardware interrupt mechanism to notify kernel of events which require attention (I/O completion, status change, real-time clock etc)

• System processes - scheduled by OS
 swapper and pagedaemon.
Fred Kuhns ( ) CS523S: Operating Systems

Trap or Interrupt Processing
• Hardware switches to kernel mode, using the per/process kernel stack. • HW saves PC, Status word and possibly other state on kernel stack. • Assembly routine saves any other information necessary and dispatches event. • On completion a return from interrupt (RFI) instruction is performed.
Fred Kuhns ( ) CS523S: Operating Systems

Interrupt handling
• Asynchronous event such as disk I/O, network packet reception or clock “tick”. • Must be serviced in system context. • Must not block. • This does take CPU time away from the currently running process!

Fred Kuhns ( )

CS523S: Operating Systems

Interrupt handling (cont)
• Multiple interrupt priority levels (ipl), traditionally 0-7. • User processes and kernel operate at the lowest ipl level. • Higher level Interrupts can preempt lower priority ones. • The current ipl level may be set while executing critical code.
Fred Kuhns ( ) CS523S: Operating Systems

Exception handling
• Synchronous to the currently running process for example divide by zero or invalid memory access. • Must run the the current processes context. • An Interrupt can occur during the processing of an exception or trap.

Fred Kuhns ( )

CS523S: Operating Systems

Software Interrupts
• Interrupts typically have the highest priority in a system. • Software interrupts are assigned priorities above that of user processes but below that of interrupts. • Software interrupts are typically implemented in software. • Examples are callout queue processing and network packet processing.
Fred Kuhns ( ) CS523S: Operating Systems

System Call Interface
• Implemented as an assembly language stub. • Trap into kernel dispatch routine which may save additional state and invoke the highlevel system call. • User privileges are verified and any data is copied into kernel (copyin()). • On return, copy out any user data (copyout()), check for an Asynchronous System Trap (signal, preemption, etc).
Fred Kuhns ( ) CS523S: Operating Systems

Synchronization
• Kernel is re-entrant. • only one active process at any given time (others are blocked). • Nonpreemptive. • Blocking operations • masking interrupts

Fred Kuhns ( )

CS523S: Operating Systems

Blocking Operations
• When resource is unavailable (possibly locked), process sets flag and calls sleep() • sleep places process blocked queue, sets state to asleep and calls swtch() • when resource released wakeup() is called • all sleep processes are woken and state set to runnable (placed on the runnable queues). • When running, process must verify resource is available.
Fred Kuhns ( ) CS523S: Operating Systems

Process Scheduling
• Preemptive round-robin scheduling • fixed time quantums • priority is adjusted by nice value and usage factor. • Processes in the kernel are assigned a kernel priority (sleep priority) which is higher than user priorities. • Kernel 0-49, user 50-127.
Fred Kuhns ( ) CS523S: Operating Systems

Signals
• • • • Asynchronous events and exceptions Signal generation using the kill() system call Default operation or user specific handlers sets a bit in the pending signals mask in the proc structure • All signals are handled before return to normal processing • System calls can be restarted
Fred Kuhns ( ) CS523S: Operating Systems

Process creation
• Fork
create a new process copy of parents virtual memory parent return value is child’s PID child return value is 0

• exec
overwrite with new program

Fred Kuhns ( )

CS523S: Operating Systems

Process Termination
• exit() is called
closes open files releases other resources saves resource usage statistics and exit status in proc structure wakeup parent calls swtch

• Process is in zombie state • parent collects, via wait(), exit status and usage
Fred Kuhns ( ) CS523S: Operating Systems

Sign up to vote on this title
UsefulNot useful