IT 개론 06
Operating Systems
손 우형
[email protected]
Where we are
• Part 1. Hardware • Part 3. Communications
• Computer 구조 • Internet
• Bit, Byte • WWW
• CPU • Security & Privacy
• Part 4. Other Issues
• Part 2. Software
• AI
• Algorithm
• Software Engineering & Agile
• OS
• Digital Transformation
• Programming Language
• Application & Cloud
Operating System
A program that controls the resources of a computer
- Interface between hardware and all other software
- DOS, Windows 3.0/3.1/95/98/NT/ME/2000/XP/Vista/7/8/10,
Unix/Linux, MacOS X, iOS, ...
Runs other programs ("applications", your programs).
Manages information on disk (file system).
Controls peripheral devices, communicates with outside.
Provides a level of abstraction above the raw hardware
- Makes the hardware appear to provide higher-level services than
it really does
- Makes programming much easier
History of General-purpose Operating Systems
1950’s: Signup sheets
- no distinction between application and operating system
1960’s: Batch operating systems
- Operators running batches of jobs
- OS/360 (IBM)
1970’s: Time-sharing
- Simultaneous access for multiple users
- Unix (Bell Labs; Ken Thompson & Dennis Ritchie)
1980’s: Personal computers, Single user systems
- DOS, Windows, MacOS
- Unix
1990’s: Personal computers, PDA’s, ...
- PalmOS, Windows CE, ...
- Unix/Linux
2000’s: Windows vs. Unix/Linux?
- MacOS X is a Unix system. Android is a Linux system
2010’s: Apple vs. Google
- iOS, Android, Chrome-OS, ... (Unix/Linux-based)
Not all computers have general-purpose operating systems
- "Embedded systems": small, specialized, but increasingly general
Unix Operating System
Developed ~1971 at Bell Labs
- by Ken Thompson and Dennis Ritchie
Clean, elegant design
- At least in the early days
Efficient, robust, easy to adapt, fun
- Widely adopted in universities, spread from there
Written in C, so easily ported to new machines
- Runs on everything (not just PC’s)
Influence
- Languages, tools, de facto standard environment
- Enabled workstation hardware business (e.g., Sun Microsystems)
- Supports a lot of Internet services and infrastructure
- Linux
Linux
A version of Unix written from scratch
- by Linus Torvalds, Finnish student (started 1991)
Source code freely available (kernel.org)
- Large group of volunteers making contributions
- Anyone can modify it, fix bugs, add features
- Torvalds approves, sets standard
- Commercial versions make money by packaging and support, not by selling
the code itself
Used by major sites, including
- Google, Amazon, Facebook, Twitter, YouTube, ABC, CBS, CNN, ...
What an Operating System does
Manages CPUs, schedules and coordinates running programs
- Switches CPU among programs that are actually computing
- Suspends programs that are waiting for something (e.g., disk, network)
- Keeps individual programs from hogging resources
Manages memory (RAM)
- Loads programs in memory so they can run
- Swaps them to disk and back if there isn’t enough RAM (virtual memory)
- Keeps separate programs from interfering with each other and with the operating
system itself (protection)
Manages and coordinates input/output to devices
- Disks, display, keyboard, mouse, network, ...
- Keeps separate uses of shared devices from interfering with each other
- Provides uniform interface to disparate devices
Manages information on disk (File System)
- Provides hierarchy of directories and files for storing information
How does an Operating System work?
Loaded into RAM & started when machine is turned on ("boot")
- So it starts out being in charge/running on the bare hardware
Querying the hardware to determine what devices are attached to the computer
- Loading software components (drivers) for connected devices
Gives control in turn to each program that is ready to run
Responds to external events/devices/…
- Does actions, relays events to programs, …
Programs (applications) request services by "making a system call"
- Execute a particular instruction (trap) that transfers control to specific part of operating system
- Parameters say what task to do
OS does operation, returns control (and result) to application
Bootstrapping: How does it all get started
CPU begins executing at specific memory location when turned on
- Location is defined by the hardware: part of the machine’s design
- Often in ROM (read-only memory) so not volatile but changeable
"bootstrap" instructions placed there read more instructions
- CPU tries to read first block from disk as bootstrap to copy more of the
operating system
- If that fails, tries to read bootstrap from somewhere else
e.g., CD-ROM, USB, network, ...
CPU Management
Fetch program to be run (usually from disk)
Load it into RAM
- Maybe only part, with more loaded as it runs (dynamic libraries)
Transfer control to it
Provide services to it while it runs
- Reading and writing info on disk
- Communications with other devices
Regain control and recover resources when program is finished
Protect itself from errant program behavior
Share memory & other resources among multiple programs running "at the same time"
- Manage memory, disks, network, ...
- Protect programs from each other
- Manage allocation of CPUs among multiple activities
Memory Management
What’s in memory? Over-simplified pictures:
Reality is more complicated
- Pieces of programs are partly in RAM, partly on disk
Can only execute instructions that are in RAM
Memory protection:
- Making sure that one program can’t damage another or the OS
Virtual memory:
- Making it look like there is more RAM than there really is
Device Management
Operating system hides physical properties of devices
- Device has specific capabilities, parameters, etc.
- Hardware and software in device and OS present these at higher level
- e.g., Printer
Logical view: put characters out in 66 lines of 80 characters
Physical view: paint individual bits of characters in raster across page
- e.g., CD-ROM
Logical view: File system just like the one on the hard drive
Physical view: Long spiral of individual bits read by a laser
OS uses device drivers to control physical devices
- Driver code has detailed knowledge of how to operate a particular device
- Implemented as functions that provide interface between specific capabilities of a device and
what the operating system expects
- Loaded as part of OS as needed, e.g., when a device is plugged in
("Windows has found new hardware")
Drivers insulate OS and application programs from specific properties of devices
Information Management
File: Sequence of bytes stored on a computer
- Content is arbitrary; any structure is imposed by the creator of the file, not by the operating
system
File system: Software that provides hierarchical storage and organization of files, usually
on a single computer
- Part of the operating system
Database: Integrated collection of logically related records
- Data is organized and structured for efficient systematic access
- May be distributed across lots of machines & geographically dispersed
Database system: Software that provides efficient access to information in a database
- Not usually part of the operating system
File Systems
Logical structure: Users and programs see a hierarchy of folders
(directories) and files
- A folder contains references to folder and files
- "root" folder ultimately leads to all others
- A file is just a sequence of bytes
Contents determined and interpreted by programs, not the operating system
- A folder is a special file that contains names of other folders & files
plus other information like size, time of change, etc.
Contents are completely controlled by the operating system
Physical structure: Disk drives operate in tracks, sectors, etc.
- Other storage devices have other physical properties
The operating system converts between these two views
- Does whatever is necessary to maintain the file/folder illusion
- Hides physical details so that programs don’t depend on them
- Presents a uniform interface to disparate physical media
The "file system" is the part of the operating system that does
this conversion
File Systems
How The File System converts Logical to
Physical
Disk is physically organized into sectors, or blocks of bytes
- Each sector is a fixed number of bytes, like 512 or 1024 or …
- Reading and writing always happens in sector-sized blocks
Each file occupies an integral number of blocks
- Files never share a block
- Some space is wasted: A 1-byte file wastes all but 1 byte of the block
If a file is bigger than one block, it occupies several blocks
- The blocks are not necessarily adjacent on the disk
Need a way to keep track of the blocks that make up the file
This is usually done by a separate "file allocation table" that lists the blocks that make up
each file
- This table is stored on disk too so it persists when machine is turned off
- Lots of ways to implement this
Converting Logical to Physical (Continued)
Every block is part of some file, or reserved by operating system, or unused
"file allocation table" keeps track of blocks
- By chaining/linking them together
First block of a file points to second, second points to third, etc.
Last block doesn’t point to a successor (because it doesn’t have one)
- Or (much more common) by some kind of table or array
that keeps track of related blocks
Also keeps track of unused blocks
- Disk starts out with most blocks unused ("free")
Some are reserved for file allocation table, etc.
- As a file grows, blocks are removed from the unused list and attached to the list for the
file.
Converting Logical to Physical: Directories
A directory/folder is a file
- Stored in the same file system
- Uses the same mechanisms
But it contains information about other files and directories
The directory entry for a file tells where to find the blocks
The directory entry also contains other info about the file
- Name (e.g., midterm.doc)
- Size in bytes, date/time of changes, access permissions
- Whether it’s an ordinary file or a directory
The file system maintains the info in a directory
- Very important to keep directory info consistent
- Application programs can change it only indirectly/implicitly
What happens when you say "Open"?
Search for file in sequence of directories as given by components of
its name
- Report an error if any component can’t be found
Read blocks of the file as needed
- Using the location information in the file allocation table to find the
blocks
- Store (some of) them in RAM
What happens when you say "Save"?
Make sure there's enough space (enough unused blocks).
- Don’t want to run out while copying from RAM to disk
Create a temporary file with no bytes in it.
Copy the bytes from RAM and/or existing file to temporary file:
while (there are still bytes to be copied) {
Get a free block from the unused list
Copy bytes to it until it’s full or there are no more bytes to copy
Link it in to the temporary file
}
Update the directory entry to point to the new file.
Move the previous blocks (of old version) to the unused list
- Or to recycle bin/trash
What happens when you remove a file?
Move the blocks of the file to the unused list.
Set the directory entry so it doesn't refer to any block
- Set it to zero, maybe
Recycle bin/trash
- Recycle bin or trash is just another directory
- Removing a file just puts the name, location info, etc., in that directory instead
"Emptying the trash" moves blocks into unused list
- Removes entry from Recycle/Trash directory
Why "removing" a file isn't enough?
- Usually only changes a directory entry
- Often recoverable by simple guesses about directory entry contents
- File contents are often still there even if directory entry is cleared
Network File Systems
Software system for accessing remote files across networks
User programs access files and folders as if they are on the local machine.
Operating system converts these into requests to ship information to/from another
machine across a network.
There has to be a program on the other end to respond to requests.
"Mapping a network drive" or "Mounting your H: drive" sets up the connections.
Subsequent reads and writes go through the network instead of the local disk.
Example) iCloud, Google Drove, Dropbox…
Databases and Database Systems
Informally, database is a large collection of information.
More formally, an organized collection of logically related records.
Data items have fixed set of attributes
- Name, address, phone number, gender, income, social security number, ...
Each record has these attributes for a single person/instance
Database systems support
- Very efficient search for records with specific properties
All the women in 08540 with income > $100K
- High volumes of traffic with concurrent access and update
"ACID": Atomic, Consistent, Isolated, Durable
Major examples
- Oracle
- SQL Server (Microsoft)
- MySQL (open source, now owned by Oracle)
- SQLite (open source, in devices like iPhone & Android)
The End of Lecture