0% found this document useful (0 votes)
27 views

Operating Systems: User Process User Process User Process User Process

The document discusses the history and evolution of operating systems from early batch processing systems to modern personal computing systems. It covers the key phases from users at the console, to batch processing, interactive time-sharing, and personal computing. Key concepts covered include system calls, interrupts, layered abstraction, and buffered I/O.

Uploaded by

abcfake123efg456
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Operating Systems: User Process User Process User Process User Process

The document discusses the history and evolution of operating systems from early batch processing systems to modern personal computing systems. It covers the key phases from users at the console, to batch processing, interactive time-sharing, and personal computing. Key concepts covered include system calls, interrupts, layered abstraction, and buffered I/O.

Uploaded by

abcfake123efg456
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Operating Systems

CS 217

Operating System (OS)


• Provides each process with a virtual machine
Promises each program the illusion of
having whole machine to itself

User User User User


Process Process Process Process

OS Kernel

Hardware

1
Operating System
• Coordinates access to physical resources
CPU, memory, disk, i/o devices, etc.

• Provides services
Protection
Scheduling User User
Memory management Process Process
File systems
Synchronization OS Kernel
etc.

Hardware

OS as Government
• Makes lives easy Randy
Promises everyone whole machine Wang
(dedicated CPU, infinite memory, …)
Provides standardized services
(standard libraries, window systems, …)

• Makes lives fair


Arbitrates competing resource demands

• Makes lives safe


Prevent accidental or malicious damage
by one program to another

2
OS History
• Development of OS paradigms: Randy
Phase 0: User at console Wang
Phase 1: Batch processing
Phase 2: Interactive time-sharing
Phase 3: Personal computing
Phase 4: ?

Computing price/performance affects OS paradigm

Phase 0: User at Console


• How things work Randy
One program running at a time Wang
No OS, just a sign-up sheet for reservations
Each user has complete control of machine

• Advantages
Interactive!
No one can hurt anyone else

• Disadvantages
Reservations not accurate, leads to inefficiency
Loading/ unloading tapes and cards takes forever and
leaves the machine idle

3
Phase 1: Batch Processing
• How things work Randy
Sort jobs and batch those with similar needs Wang
to reduce unnecessary setup time
Resident monitor provides “automatic job sequencing”:
it interprets “control cards” to automatically run a bunch
of programs without human intervention

• Advantage
Good utilization of machine

• Disadvantagess
Loss of interactivity (unsolvable) Good
Good for
for
One job can screw up other jobs, expensive
expensive hardware
hardware
need protection (solvable) and
and cheap
cheap humans
humans

Phase 2: Interactive Time-Sharing


• How things work Randy
Multiple users per single machine Wang
OS with multiprogramming and memory protection

• Advantages:
Interactivity
Sharing of resources

• Disadvantages:
Does not always provide
reasonable response time Good
Good for
for
cheap
cheap hardware
hardware
and
and expensive
expensive humans
humans

4
Phase 3: Personal Computing
• How things work Randy
One machine per person Wang
OS with multiprogramming and memory protection

• Advantages:
Interactivity
Good response times

• Disadvantages:
Sharing is harder Good
Good for
for
very
very cheap
cheap hardware
hardware
and
and expensive
expensive humans
humans

Phase 4: What Next?


• How will things work? Randy
Many machines per person? Wang
Ubiquitous computing?

• What type of OS?

Good
Good for
for
very,
very, very
very cheap
cheap hardware
hardware
and
and expensive
expensive humans
humans

5
Layers of Abstraction

Appl Prog
User
process Stdio Library FILE * stream

File System hierarchical file system


Kernel Storage variable-length segments

Driver disk blocks

Disk

System Calls
• Processor modes
user mode: can execute normal instructions and
access only user memory
supervisor mode: can also execute privileged
instructions and access all of memory (e.g., devices)

• System calls
user cannot execute privileged instructions
users must ask OS to execute them - system calls
system calls are often implemented using traps
OS gains control through trap, switches to supervisor
model, performs service, switches back to user mode,
and gives control back to user

6
System Calls
• Method by which user processes invoke kernel
services: “protected” procedure call
Appl Prog
fopen,fclose, printf,
fgetc, getchar,…
Stdio Library
user open, close, read,
kernel write, seek
File System

• Unix has ~150 system calls; see


man 2 intro
/usr/include/syscall.h

Interrupt-Driven Operation
• Everything OS does is interrupt-driven Randy
System calls use traps to interrupt Wang

• An interrupt stops the execution dead in its tracks,


control is transferred to the OS
Saves the current execution context in memory
(PC, registers, etc.)
Figures out what caused the interrupt
Executes a piece of code (interrupt handler)
Re-loads execution context when done,
and resumes execution

7
Interrupt Processing
Randy
Wang

System Calls (cont)


• Parameters passed…
in fixed registers
in fixed memory locations
in an argument block, w/ block’s address in a register
on the stack

• Usually invoke system calls with trap instructions


ta 0
with parameters in %g1 (function), %o0..%o5,
and on the stack

• Mechanism is highly machine-dependent

8
Read System Call
• Read call
nread = read(fd, buffer, n);

• Reads n bytes from fd into buffer


returns number of bytes read, or –1 if there’s an error

• In the caller
mov fd,%o0
mov buffer,%o1
mov n,%o2
call read; nop
mov %o0,nread

Read System Call (cont)


• User-side implementation (libc)
read: set 3,%g1
ta 0
bcc L1; nop
set _errno,%g1
st %o0,[%g1]
set –1,%o0
L1: retl; nop

• Kernel-side implementation
sets the C bit if an error occurred
stores an error code in %o0
(see /usr/include/sys/errno.h)

9
Write System Call
int safe_write(int fd, char *buf, int nbytes)
{
int n;
char *p = buf;
char *q = buf + nbytes;
while (p < q) {
if ((n = write(fd, p, q-p)) > 0)
p += n;
else
perror(“safe_write:”);
}
return nbytes;
}

Buffered I/O
• Single-character I/O is usually too slow

int getchar(void) {
char c;
if (read(0, &c, 1) == 1)
return c;
return EOF;
}

10
Buffered I/O (cont)
• Solution: read a chunk and dole out as needed
int getchar(void) {
static char buf[1024];
static char *p;
static int n = 0;

if (n--) return *p++;

n = read(0, buf, sizeof(buf));


if (n <= 0) return EOF;
n = 0;
p = buf;
return getchar();
}

Standard I/O Library


#define getc(p) (--(p)->_cnt >= 0 ? \
(int)(*(unsigned char *)(p)->_ptr++) : \
_filbuf(p))

typedef struct _iobuf {


int _cnt; /* num chars left in buffer */
char *_ptr; /* ptr to next char in buffer */
char *_base; /* beginning of buffer */
int _bufsize;/* size of buffer */
short _flag; /* open mode flags, etc. */
char _file; /* associated file descriptor */
} FILE;
extern FILE *stdin, *stdout, *stderr;

11
Summary
• OS virtualizes machine
Provides each process with illusion of having whole
machine to itself

• OS provides services
Protection
Sharing of resources
Memory management
File systems
etc.

• Protection achieved through separate kernel


User processes uses system calls to ask kernel
to access protected stuff on its behalf

12

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy