Introduction

Download Report

Transcript Introduction

Chapter 1
Introduction
1.1 What is an operating system
1.2 History of operating systems
1.3 The operating system zoo
1.4 Computer hardware review
1.5 Operating system concepts
1.6 System calls
1.7 Operating system structure
1
Introduction
• A computer system consists of
– hardware
– system programs
– application programs
2
What is an Operating System
• It is an extended machine
– Hides the messy details which must be performed
– Presents user with a virtual machine, easier to use
• It is a resource manager
– Each program gets time with the resource
– Each program gets space on the resource
3
History of Operating Systems (1)
• First generation 1945 - 1955
– vacuum tubes, plug boards
• Second generation 1955 - 1965
– transistors, batch systems
• Third generation 1965 – 1980
– ICs and multiprogramming
• Fourth generation 1980 – present
– personal computers and workstations (Network
operating systems and distributed operating
systems)
4
History of Operating Systems (2)
Early batch system
–
–
–
–
bring cards to 1401
read cards to tape
put tape on 7094 which does computing
put tape on 1401 which prints output
5
History of Operating Systems (3)
• Structure of a typical FMS job – 2nd generation
6
History of Operating Systems (4)
• Multiprogramming system
– three jobs in memory – 3rd generation
7
Fourth generation 1980 – Present
• Operating systems for personal computers
–
–
–
–
–
CP/M (Control Program for Microcomputers)
DOS (Disk Operating System)  MS-DOS
GUI (Graphical User Interface)
Windows  Windows 95/98/Me
Windows NT  Windows 2000 Windows
XP
– UNIX:
• X Windows, Motif
• Linux, Gnome, KDE
8
The Operating System Zoo
• Mainframe operating systems
– Example: OS/390, OS/360
• Server operating systems
– Example: UNIX, Windows 2000, Linux
• Multiprocessor operating systems
• Personal computer operating systems
– Windows 98, 2000, XP, Macintosh, Linux
• Real-time operating systems
– Hard real-time system: the action absolutely must occur
at a certain moment.
• Embedded operating systems
– PalmOS, Pocket PC for PDA
• Smart card operating systems
– Java Virtual Machine (JVM)
9
Computer Hardware Review (1)
Monitor
Bus
• Components of a simple personal computer
10
Computer Hardware Review (CPU)
(a) A three-stage pipeline
(b) A superscalar CPU
11
Computer Hardware Review (Memory)
• Typical memory hierarchy
– numbers shown are rough approximations
12
Computer Hardware Review (disk)
Structure of a disk drive
13
Computer Hardware Review (5)
One base-limit pair and two base-limit pairs
14
Computer Hardware Review (I/O)
(a)
(b)
(a) Steps in starting an I/O device and getting interrupt
(b) How the CPU is interrupted
15
Computer Hardware Review (Buses)
Structure of a large Pentium system
16
Operating System Concepts (Processes)
• A process is a program in execution.
• The information about a process is stored in an
operating system table called the process table.
• A process called the command interpreter or
shell read commands from a terminal.
• If a process can create one or more other process
(child processes) and these process create child
processes, we can build them in a tree structure.
• In UNIX, there is a parent process for all
processes.
17
Operating System Concepts (Processes)
• A process tree
– A created two child processes, B and C
– B created three child processes, D, E, and F
18
Processes Tree on a UNIX System
19
Operating System Concepts (Processes)
• The communication to cooperate and synchronize
processes is called interprocess communication.
• A signal causes the process to suspend and run a
special signal handling procedure.
• Each person authorized to use a system is assigned
a UID (User IDentification). A process is assigned
a PID (Process IDentification).
• Users can be members of groups, each of which
has a GID (Group IDentification).
• The superuser (root in UNIX) has special
privilege to violate many of the protection rules.
20
Operating System Concepts (Deadlocks)
• When two or more processes get themselves into
a stalemate situation, they are in deadlock.
(a) A potential deadlock. (b) an actual deadlock.
21
Operating System Concepts (Memory &
Files)
• In virtual memory the operating system keeps part
of the address space in main memory and part on
disk.
• A file system provides users with a nice, clean
abstract model of device-independent files.
• A directory is used to group files together.
• A path name can specify the location of a file.
• A root directory is the top of the directory
hierarchy. In Unix, / is the root directory.
• Each process has a current working directory
(pwd).
22
Operating System Concepts (Files)
File system for a university department
23
Operating System Concepts (Files)
• If a file access is permitted, the system return
small integer called a file descriptor to use in
subsequent operations.
• In UNIX the mounted file system is used to deal
with removable media (mount).
• Two kinds of special files exist in UNIX under the
/dev directory: block special files (disks) and
character special files (printers, modems).
• A pipe is a sort of pseudo file that can be used to
connect two processes (ps –aef | more).
24
Operating System Concepts (Files)
• Before mounting,
– files on floppy are inaccessible
• After mounting floppy on b,
– files on floppy are part of file hierarchy
25
Operating System Concepts (Pipes)
Two processes connected by a pipe
26
Operating System Concepts (Security &
Shell)
• Files in UNIX are protected by a 9-bit binary
protection code.
– The protection code consists of three 3-bit fields, one
for owner, one for group, and one for others.
– Each field has a bit for read, a bit for write, and a bit for
execute. They are known as rwx bits.
• The UNIX command interpreter is called the shell.
• Many shells exist, including sh, csh, ksh, and bash.
• The user can use < and > to redirect the standard
input and output. The ampersand (&) can be put
after a command to start it as a background job.
27
System Calls
• System calls provide the interface between a
running program and the operating system.
– Generally available as assembly-language
instructions.
– Languages defined to replace assembly
language for systems programming allow
system calls to be made directly (e.g., C, C++).
28
Steps in Making a System Call
There are 11 steps in making the system call
read (fd, buffer, nbytes)
29
Types of System Calls
•
•
•
•
Process management
File management
Directory or Device management
Miscellaneous
– Information maintenance
– Communications
• Some POSIX (Portable Operating System
Interface) are listed as follows.
30
Some System Calls For Process Management
31
Some System Calls For File Management
32
Some System Calls For Directory Management
33
Some System Calls For Miscellaneous Tasks
34
System Calls for Process
•
•
•
•
Process management
File management
Directory or Device management
Miscellaneous
– Information maintenance
– Communications
• Some POSIX (Portable Operating System
Interface) are listed as follows.
35
System Calls for Process
• Fork creates a duplicate of the original process.
• UNIX examples (Fig4-8.c)
– fork system call creates new process.
– exec system call used after a fork to replace the
process’ memory space with a new program.
– wait system call used to move the parent process off the
ready queue until the termination of the child.
• Exit system call is used when a process is finished
executing.
• Try the ps command.
36
System Calls (Process)
• A stripped down shell:
while (TRUE) {
type_prompt( );
read_command (command, parameters)
/* repeat forever */
/* display prompt */
/* input from terminal */
if (fork() != 0) {
/* Parent code */
waitpid( -1, &status, 0);
} else {
/* Child code */
execve (command, parameters, 0);
}
}
/* fork off child process */
/* wait for child to exit */
/* execute command */
37
Forking Processes
/* fork processes */
main()
{
int i, pid;
for (i=1; i<=3; i++) {
if ((pid = fork()) == 0) {
printf("In child %d. \n", i);
}
}
}
38
Forking Processes
P
I=2
I=1
I=2
I=3
I=3
I=3
I=3
39
System Calls for Process
• Processes in UNIX have their memory
divided up into three segments:
– The text segment (the program code)
– The data segment (the variables) grows
upwards.
– The stack segment (functions) grows
downwards.
40
System Calls (Process)
• Processes have three segments: text, data, stack
41
System Calls (Directory)
link(“/usr/jim/memo”, “/usr/ast/note”);
(a) Two directories before linking
/usr/jim/memo to ast's directory
(b) The same directories after linking
42
System Calls (Device)
mount(“/dev/fd0”, “/mnt”, 0)
(a) File system before the mount
(b) File system after the mount
43
System Calls (Win32)
Some Win32 API calls
44
Operating System Structure
• Monolithic System - "the big mess". All operating
system operations are put into a single file. The
operating system is a collection of procedures,
each of which can call any of the others.
• Layered System - The operating system is
organized as a hierarchy of layers of processes.
– THE operating system
• Virtual Machine - The operating system is a
timesharing system that provides: (a)
multiprogramming and (b) an extended machine.
– MS-DOS virtual mode
– JVM (Java Virtual Machine)
45
Operating System Structure
(Monolithic)
Simple structuring model for a monolithic system
46
Operating System Structure (Layer)
Structure of the THE operating system
47
Operating System Structure
• Exokernels - The only job of the operating
system is to securely allocate the hardware
resources.
– Transmeta ?
• Client-server Model - The operating system
is collection of servers that provide specific
services; e.g., file server, etc.
• Advantages of client-server model:
– Servers are running in user mode. If they crash,
the system won’t crash.
– Adapt to use in distributed systems.
48
Operating System Structure (Virtual
Machine)
Structure of VM/370 with CMS
49
Operating System Structure (Clientserver)
The client-server model
50
Operating System Structure (ClientServer)
The client-server model in a distributed system
51
Research on Operating Systems
• Most of the papers cited in the research
sections were published
– ACM – http://www.acm.org
– the IEEE Computer Society –
http://www.computer.org
– USENIX – http://www.usenix.org
• Microkernel can be made flexible and
dependable. It is the current trend.
52
Metric Units
• The metric prefixes are typically abbreviated by
their first letters, with the units greater than 1
capitalized.
• m is for milli and µ is for micro.
• For memory, Kilo means 210. For communication,
1-Kbps means 1000 bits per second.
53
Summary: Operating System
Components
• Main operating system components:
– process manager
– memory manager
– file system
54
Summary: Operating System
Components
• A process manager controls the creation,
execution, and deletion of processes. A
process is a program in execution,
consisting of:
–
–
–
–
the executable program,
the program's data and stack,
PC, SP, and other CPU registers,
all other information needed to run the
program.
55
Summary: Operating System
Components
• A process table is a data structure in the operating
system that is used to store information about
processes – register contents and all other
information needed to run the process.
• Try experiments Ex1.c and Ex2.c in programs.
– Compile using: cc -o forever Ex1.c
–
cc -o sleepy Ex2.c
• Execute in the background: forever &
• Print the manual entry for ps: man ps | col -b | lpr
–P1 and check the process status for forever.
• Print the manual entry for kill and kill the forever
process.
56
Summary: Operating System
Components
• For Ex2.c, look at /usr/include/sys/signal.h.
• Note that SIGALRM=14, so we can kill sleepy early by
sending signal 14 to process sleepy: kill -14 <pid> where
<pid> is the process id of sleepy found by executing ps.
• The memory manager manages memory allocation and
deallocation.
– Most operating systems support multiprogramming to improve
CPU efficiency. Multiprogramming simply means that several
processes are in memory at the same time.
– The memory manager uses swapping and paging to decide which
processes (or parts of processes) core images to move between
memory and disk.
– The motivation is to allow processes which do not fit in memory to
be executed anyway and to allow multiprogramming.
57
Summary: Operating System
Components
• The file system controls access to files on
external storage devices, such as disks.
Directories are used to organize files.
Security and protection is attained by:
– assigning each user a unique ID, called a user id
(UID),
– assigning owners (users) to processes and files,
and
– using a protection mechanism, such as Access
Control Lists (ACL) or Capabilities, to restrict
access to processes and files.
58