A program that acts as an intermediary between a user of a computer and the computer hardware.
- Execute user programs and make solving user problems easier
- Make the computer system convenient to use - providing a convenient working environment for all users
- Use the computer hardware efficiently - efficient allocation and management of the resources
Four components of a computer system
3. Application programs
- The system software in-charge of the computer system
- A resource allocator: manages all resources, decides between conflicting requests for efficient and fair resource use
- A control program: controls execution of programs to prevent errors and improper use of the computer/resources.
Definition of an OS
- No universally accepted definition
- Everything a vendor ships when you order an OS
The one program running at all times on the computer; everything else is either a system or application program.
Other system and application programs are built upon
A command line interpreter used to interact with the OS (Bourne, C, Bourne-Again, Korn)
OS are found in and have roles in
Single user systems, Multi-user systems, Embedded and handheld systems.
Computer start up
Bootstrap program is loaded at power-up or reboot
Typically stored in ROM and EPROM, known as firmware
Initializes all aspects of the system
Loads operating system's kernel and starts execution by running the first process (init).
One of more CPUs, device controllers, buses, shared memory
Concurrent execution of CPUs and devices competing for memory cycles
Event occurrence is signaled by an interrupt. Interrupt transfers control to the interrupt service routine via interrupt vector containing addresses of all service routines. Must save address of interrupted instruction (save/restore state).
Incoming interrupts are disabled while another interrupt is being processed to prevent a lost interrupt.
Software-generated interrupt caused by either an error or a user request (system/monitor call).
Interrupt by sending a signal to the CPU via the system bus.
Only large storage media CPU can access directly
Extension of main memory that provides large nonvolatile storage capacity.
Storage systems hierarchy
Smaller and more expensive as you go up, and faster.
Larger and less expensive as you go down, slower.
Electronic Disk can be nonvolatile or volatile, but above it is volatile and below it is nonvolatile.
Copying information into a faster storage system.
Cache for main memory
Main memory cache for secondary storage.
Extension for multiprogramming; user interacts with the system using a terminal.
Gives the illusion of having a computer for themselves. Switches so fast that it looks like that.
Requires the OS to do CPU scheduling.
Program in execution; a dynamic entity with a life-time; has several resources allocated (RAM space, CPU cycles, etc).
Process = task = program in execution
Concurrent execution - not parallel execution
OS should manage processes - create, kill, suspend, communicate.
A static file residing on a disk.
From PDA's to mainframes - many. Have special purpose processors as well.
Parallel or tightly coupled systems. Two or more processors in close communication, sharing bus, sometimes clock, memory and peripheral devices.
Advantages of Multiprocessor systems
- Increased throughput
- Cost less than multiple single-processor systems
- Increased reliability
Each processor is assigned a specific task, controlled by a master processor.
Master schedules and allocates work to slave processors.
(SMP) Each processor performs all taks in the OS
All processors are peers
I/O Control, scheduling/load balancing
UNIX, Windows, LINUX, MAC OS X
Multiple programming cores
Very similar to multiprocessor chips.
More efficient than multiple single core chips as on-chip communication is faster, consumes less power.
Pressure on OS, application programmers to make use of all CPU resources.
Dual mode operation of the CPU
User mode - only subset of machine instructions available.
Kernel (supervisor, system) mode - complete access to all hardware and can execute and instruction.
Privileged and non-privileged instructions.
Added to hardware to indicate current mode: kernel (0), user (1).
Used to distinguish if system or user code is being run by the system.
System call changes mode to kernel, return from call resets it to user.
Load Accumulator, store Accumulator, jump instruction, NOP instruction, etc.
Only executed in kernel mode, else a trap occurs.
Writing to lower memory addresses
Working with I/O
When a system call is made it is treated as a software interrupt and a specific service routine in the OS is executed (starting with the mode bit to kernel mode).
Privileged Instruction in user mode
Will cause a trap.
The kernel of the OS runs in kernel/system mode, all other components of the OS run in user mode.
OS maintains control over the CPU - cannot allow a program to get stuck in an infinite loop, fail to call system services or never return control to the OS.
Before giving control to the user the OS sets a timer to interrupt after a specific time period. Thus, guarantees that after a certain time control transfers to the OS.
Upon a timer interrupt the OS can decided that the process has run too long and stop it, or give it more time/resources.
Still a user with increased privileges and accesses whose programs still run in user mode.
Programmed I/O with busy waiting (or polling)
Each unit of data moved in or out is handled by the CPU directly.
Device has its data register and a one-bit flag (status). Sets flag to 1/0 to indicate busy/ready. The CPU spends most of the time in a loop, monitoring the flag bit in the device to see if data needs to be transferred (busy waiting). CPU wasting time/idle, it could be processing another task.
Used in low-end embedded systems where CPU has very little work to do. Memory mapped I/O.
Signal/interrupt is sent to the CPU on a wire/bus called the interrupt request line, which the CPU checks after executing every instruction.
Save current program status
Determine interrupt type, load starting address of interrupt processing routine in program counter, switch mode
Disable all interrupts or enable higher priority interrupts
Do required processing for the interrupt type
Restore old program status (context switch), enable interrupts
Expensive: used if interrupts arrive at a fairly low rate (Keyboard)
Direct Memory Access (DMA) I/O
Used for large memory transfers when it is wasteful for CPU to watch status bits/transfer one byte at a time
DMA controller is capable of accessing memory/memory bus directly.
CPU instructs the DMA in direction of data transfer, device to interact with, number of bytes to be moved, RAM buffer address for data.
Responsible for data transfer
Completes work and sends an interrupt to the CPU
Will slow the CPU because of contention for access to memory and system bus (DMA is given preference - cycle stealing)
CPU can delay processing interrupts by masking off the interrupts.
Most machines support the concept of priorities for interrupts
Switching from user to OS
Hardware interrupt - signal sent by I/O device/DMA. Can be masked off
Trap - program encounters an error. Can be masked off. Swft Interrupt
System call - Deliberate request. Swft Interrupt
OS Design Issues
Depends on User goals (speed, convenience, ease of use, etc) and System goals (cost, single/multi-user, time-shared, real-time, etc)
Simple Monolithic Structure - maximum functionality in least space. functionality not well separated (system crashes if user programs are buggy). no dual mode or hardware protection.
Layered - divided into a number of layers, each built on top of lower layers. highest layer is the user interface and lowest level is the hardware. layers use only functions/operations of those at lower levels. information hiding, easy debugging, design is not obvious, less efficient.
Micro-Kernel - remove all non-essential components from the kernel and implement them as user-level programs. increased security and reliability as most services are running as user processes (if fail, does not crash the whole system). Easy extension of OS as they are added to user space and no kernel modification is necessary.
Virtual Machine (VM)
Many copies of the (abstract) hardware of a single computer that can be used in different environments. The host OS creates the illusion that a process has its own processor and memory.
Each guest provided with a (virtual) copy of underlying computer.
Cost effective, reliability increase - Single machine running many VMs .
System generation - process of configuring or generating a system for each specific computer site.
Compatible Time Sharing System (CTSS) project at MIT.
Ken Thompson and Dennis Ritchie
UNIX OS = Kernel + Shell
Simple user interface
All date files are counted as the number of days since Jan 1, 1970 - UNIX bday.
Protable OS interface for Unix like systems.
IEEE developed, most UNIX like systems support.
uname - command for system information
chmod - change permissions of a file/directory
passwd - change password
UNIX file structure
Hierarchical file structure with mountable files.
Tree-like structure starting with the root '/'. Mounts other file systems to the foot file system (mount system call).
Can change where input/output comes/goes by using '>,<'.
Pipes using '|' join standard output of one process to the standard input of another
Input - takes input from file
Output - sends input to a file
Pipe - ls -l | wc -l : ls piped into wc
UNIX User authentication
Sign on - need userid (login id, username) and password
Verify password and establish user's individual and group identity (uid, gid)
Encrypted password file
rwx access modes
Standard input normally bound to keyboard. Standard output and Standard error normally bound to monitor.
File pointers such as stdin, stdout, stderr defined in stdio.h.
UNIX views each regular file as a sequence of bytes; there is no special character to mark the end of a file.
When a file is opened, we obtain a file descriptor number which is a small int value to be used as an index in a file descriptor table for the process.
The smallest unused file descriptor number is assigned.
Same physical can be opened more than once within a process (two or more system calls). The two opens will be kept track of separately.
For a particular open of a file, we have a file descriptor assigned at the time of open. dup system call allows an additional file descriptor to be assigned for the same file open.
int open(char* name, int access, int permission);
int close(int fd);
int read(int fd, char *buffer, int count);
int write(int fd, char *buffer, int count);
Data in UNIX
Organized as files, directories and sub-directories
9(10 total) permission bits associated with each file which specify what operations may be performed and by whom.
r - read bit
w - write bit
x - execute bit
Bits for owner, group and other (everyone else)
-rw------- 1 scott staff 1256 Junn 4 18:16 x
regular file, owner scott, group staff, file x = only scott can read and write
d in front is a directory
r = 4
w = 2
x = 1
chmod 7777 test = -rwsrwsrwt
chmod 1000 test = ---------T
chmod 2000 test = ------S---
chmod 4000 test = ---S------
Owners and Groups
UNIX keeps tracks of owners and groups as numbers rather than text names.
Text names are for human convenience.
UID: User Identification numbers are mapped to user names in the etc/passwd file. UID of root = 0.
GID: Group Identification numbers are mapped to group names in etc/group file.
When file ownership has to be displayed the ls -l command looks into the appropriate file/database for the associated text
4 Identities of processes
Effective UID and GID determine/control what resources the process has access to.
Real UID and GID are used for account purposes.
Usually UID=EUID and GID=EGID.
setuid bit - unprivileged users sometimes need to accomplish a task that requires special privileges (password change). x bit is set to an s. S if no permissions are already there.
If an s bit is set, an ordinary user assumes the power of the owner (thus the access of the user goes up).
If s bit is off, UID=EUID
If s bit is on, UID != EUID; EUID=owner of file with s bit set.
Only readable by the root to prevent dictionary attacks and make the systems more secure. Stores encrypted passwords. One-to-one correspondence with etc/passwd file.
Fork - fork(); on return from the fork system call, the parent (process invoking the fork) and the child (newly created process) are identical except for their pids. Returns a single value for each process -- 0 for the child and the pid of the child to the parent.
Wait - wait(&staus); status is an integer. The call returns the pid of the terminated child.
Excelp -excelp(filename, commandname, command args); will overlay the existing program with a new command (2nd param) from the file (first param) and deliver the other arguments provided. End of the arguments is indicated by a null pointer.
Open - open(name, accessmode, protection); name is a char string of the file name. accessmode is 0 for read, 1 for write, 2 to open. Third param is only if the file is being created
Close -close(fd); close the file whose file descriptor is fd.
Pipe - pipe(pipefd); pipefd is a int array or two components. First will contain the fd to be used for reading from the pipe and the second will contain the fd to be used for writing to the pipe.