Outline • Introduction to Operating Systems • Using the Operating Systems

advertisement
Outline
• Introduction to Operating Systems
• Using the Operating Systems
– The abstract model of computing
– System calls
System Overview
• A computer system consists of hardware and
software that are combined to provide a tool
to solve specific problems
– Hardware includes CPU, memory, disks, printers,
screen, keyboard, mouse ...
– Software includes
• System software
– A general environment to create specific applications
• Application software
– A tool to solve a specific problem
5/29/2016
COP4610
2
System Overview – cont.
5/29/2016
COP4610
3
Hardware Resources
• Processor: execute instructions
• Memory: store programs and data
• Input/output (I/O)controllers: transfer to and
from devices
• Disk devices: long-term storage
• Other devices: conversion between internal
and external data representations
5/29/2016
COP4610
4
Hardware Resources – cont.
5/29/2016
COP4610
5
Hardware Interface – cont.
• Everything that a programmer needs to know
in order to write programs that perform
desired operation on the hardware
– Disk drive is an example
• Disk interface provides functions to move disk head,
transfer data
– Monitor
• Monitor interface provides functions to move the
cursor, display characters/graphics
5/29/2016
COP4610
6
Software Classification
• System software
– Provides a general programming environment in
which programmers can create specific
applications
• Application software
– Intended to solve a specific problem
5/29/2016
COP4610
7
Software Classification - continued
5/29/2016
COP4610
8
What is an Operating System?
• The operating system is the part of the
system software that manages the use of the
hardware used by other system software and
all application software
– It is the system program that acts between the
hardware and the user programs
5/29/2016
COP4610
9
What is an Operating System? - continued
• It provides services to user programs
– Through system calls / message passing
• File system services
• Memory services
• I/O services
• It hides hardware from user programs
– When your program shows a message on the monitor, it
does not need to know the details
– When your program generates a new file, it does not need
to know where the free space is on your hard drive
5/29/2016
COP4610
10
Differences between OS and System Software
• Major differences between OS and general
system software
– OS abstracts the hardware directly
– General system software relies on the
abstractions provided by OS
– OS provides the fundamental trusted mechanisms
for resource sharing
– A general purpose OS is domain-independent
5/29/2016
COP4610
11
Operating System Functions
• Resource manager
– manage hardware and software resources
– Resource abstraction and sharing
• A nicer environment
– implement a virtual machine for processes to run in
• A program in execution is called a process
– a nicer environment than the bare hardware
5/29/2016
COP4610
12
Resource Management Functions
• Transform physical resources to logical
resources
– Resource abstraction
• Make the hardware resources easier to use
• Multiplex one physical resource to several
logical resources
– Create multiple, logical copies of resources
• Schedule physical and logical resources
– Decide who gets to use the resources
5/29/2016
COP4610
13
Resource Abstraction
• Provides an abstract model of the operation
of hardware components
– Like data abstraction in Object-Oriented
programming
• Interface functions
• Internal functions and status
5/29/2016
COP4610
14
A Disk Device Abstraction
• Three interface functions
– Load(block, length, device)
– seek(device, track)
– out(device, sector)
5/29/2016
COP4610
15
A Disk Device Abstraction – cont.
• An abstract function for writing
5/29/2016
COP4610
16
Resource Abstraction – cont.
• Multi-level abstractions
– Disk controller -> disk driver -> file system
5/29/2016
COP4610
17
Resource Sharing
• Two types of sharing
– Time multiplexed sharing
• time-sharing
• schedule a serially-reusable resource among several
users
– Space multiplexed sharing
• space-sharing
• divide a multiple-use resource up among several users
5/29/2016
COP4610
18
Time-multiplexing the Processor
- Called multiprogramming
5/29/2016
COP4610
19
Time-multiplexing the Processor – cont.
- Resulted in concurrent execution or concurrency
5/29/2016
COP4610
20
Time-multiplexing the Processor – cont.
- Multiprogramming can improve the overall system performance
5/29/2016
COP4610
21
Space-multiplexing Memory
5/29/2016
COP4610
22
Time-multiplexing I/O Devices
5/29/2016
COP4610
23
Space-multiplexing the Disk
5/29/2016
COP4610
24
Issues in Resource Sharing
• Resource isolation and sharing
– Protection
– Sharing
• Resource allocation
– Scheduling
5/29/2016
COP4610
25
Do We Need an OS?
• Not always
– When resource abstraction or sharing is not
needed
– Some programs run “stand-alone”
– Early computers did not have a sophisticated OS
– OS was evolved along the hardware technology
• But they are very useful
– Reusable functions
– Easier to use than the bare hardware
5/29/2016
COP4610
26
Operating Systems Strategies
• Several different strategies have been used
– Earliest computers were dedicated to a single
program and there was no multiprogramming and
no OS
– Batch systems
– Timesharing systems
– There are a few other recent strategies
•
•
•
•
5/29/2016
Personal computers and workstations
Embedded systems
Small, communicating computers
Network technology
COP4610
27
Batch Processing Systems
• Reduce setup time by batching similar jobs
• Automatic job sequencing – automatically
transfers control from one job to another.
First rudimentary operating system.
• Resident monitor
– initial control in monitor
– control transfers to job
– when job completes control transfers back to
monitor
5/29/2016
COP4610
28
Batch Processing Systems - continued
5/29/2016
COP4610
29
Memory Layout for a Simple Batch System
5/29/2016
COP4610
30
Spooling
• Overlap I/O of one job with computation of
another job. While executing one job, the OS
– Reads next job from card reader into a storage
area on the disk (job queue).
– Outputs printout of previous job from disk to
printer.
• Job pool – data structure that allows the OS
to select which job to run next in order to
increase CPU utilization
5/29/2016
COP4610
31
Multi-programmed Batch Systems
Several jobs are kept in main memory at the same time, and the
CPU is multiplexed among them.
5/29/2016
COP4610
32
OS Features for Multi-programming
• I/O routine supplied by the system
• Memory management – the system must
allocate the memory to several jobs
• CPU scheduling – the system must choose
among several jobs ready to run
• Allocation of devices
5/29/2016
COP4610
33
Time-sharing Systems
• The goal is to enable users to interact with the
computer system
– Batch processing systems do not allow user interactions
• On-line communication between the user and the
system is provided
– When the operating system finishes the execution of one
command, it seeks the next “control statement” not from
a card reader, but rather from the user’s keyboard.
• On-line system must be available for users to access
data and code.
5/29/2016
COP4610
34
Time-sharing Systems - continued
5/29/2016
COP4610
35
Personal-computer Systems
• Personal computers – computer system dedicated
to a single user.
• I/O devices – keyboards, mice, display screens,
small printers.
• User convenience and responsiveness.
• Can adopt technology developed for larger
operating system
– often individuals have sole use of computer and do
not need advanced CPU utilization of protection
features.
5/29/2016
COP4610
36
Personal-computer Systems - continued
5/29/2016
COP4610
37
Embedded Systems
• Often used as a control device in a dedicated application
such as controlling scientific experiments, medical imaging
systems, industrial control systems, and some display
systems.
• Well-defined fixed-time constraints.
• Hard real-time system.
– Secondary storage limited or absent, data stored in short-term
memory, or read-only memory (ROM)
– Conflicts with time-sharing systems, not supported by generalpurpose operating systems.
• Soft real-time system
– Limited utility in industrial control or robotics
– Useful in applications (multimedia, virtual reality) requiring
advanced operating-system features.
5/29/2016
COP4610
38
Parallel systems
• Multiprocessor systems with more than one CPU in
close communication.
• Tightly coupled system – processors share memory
and a clock; communication usually takes place
through the shared memory.
• Advantages of parallel system:
– Increased throughput
– Economical
– Increased reliability
• graceful degradation
• fail-soft systems
5/29/2016
COP4610
39
Distributed Systems
• Distribute the computation among several physical
processors
• Loosely coupled system – each processor has its
own local memory; processors communicate with
one another through various communications lines,
such as high-speed buses or telephone lines
• Advantages of distributed systems
–
–
–
–
Resources Sharing
Computation speed up – load sharing
Reliability
Communications
5/29/2016
COP4610
40
Distributed systems - cont.
• Network operating system
– provides file sharing
– provides communication scheme
– runs independently from other computers on the
network
• Distributed operating system
– less autonomy between computers
– gives the impression there is a single operating
system controlling the network.
5/29/2016
COP4610
41
Migration of Operating-System Concepts and Features
5/29/2016
COP4610
42
Genesis of Modern OS
5/29/2016
COP4610
43
Using the O.S.
• For a programmer, the operating system
interface is most important
– The functions provided by the OS
– Abstract resources that are available
5/29/2016
COP4610
44
Requesting Services from O.S.
• Two techniques
– System call
– Message passing
5/29/2016
COP4610
45
Requesting Services – cont.
• Two techniques
– System call
– Message passing
5/29/2016
COP4610
46
System Call Interface
• System call interface
– Operating system provides a set of operations
called system calls
– A programming interface
5/29/2016
COP4610
47
How to Make a System Call
• For a programmer
– A system call is similar to a procedure/function
call in a traditional programming language
– System calls are available in C/C++ as library
routines
– For example, fork to create a new process
5/29/2016
COP4610
48
How to Make a System Call – cont.
Do the parent and the child have the
pid = fork();
same sequence of instructions when
if (pid == ((pid_t)-1)) {
// Something must be wrong
withisthe
fork
fork()
successful?
// error processing
Why do we say this is the child and this
.........
} else {
the parent?
if (pid == 0) {
How about here?
// This is the child process
........
} else {
// This is the parent process
.........
}
//How about here, the parent or the child ?
...........
}
5/29/2016
COP4610
49
System Call Overview
• man –s 2 intro
– List of all the system calls available
•
•
•
•
•
Process management system calls
Memory management system calls
File and I/O system calls
Communication system calls
Information maintenance system calls
5/29/2016
COP4610
50
Process Management System Calls
–
–
–
–
–
–
–
fork – Create a new process
exit – Terminate a process
wait – Wait for a child process to terminate
exec – Execute a file
nice – Change scheduling priority for a process
_lwp_create – Create a new lightweight process
yield – Yield execution to another lightweight
process
5/29/2016
COP4610
51
Thread Related Functions and System Calls
• POSIX Thread
– pthread_create
– pthread_join
– pthread_exit
• Solaris Thread
– thr_create
– thr_join
– thr_exit
5/29/2016
COP4610
52
Memory Management System Calls
– brk – Change the size of data segment of process
– memcntl – Memory management control
– mmap – Map pages of memory
• (Memory mapped I/O)
– Note: malloc and free are library functions using
memory management system calls
5/29/2016
COP4610
53
File Management System Calls
–
–
–
–
–
–
open – Open a file for reading or writing
creat – Create a new file and open it
read – Read bytes from an open file
write – Write bytes to an open file
close – Close an open file
seek – Change the location in the open file of the
next read or write
– stat – Get information about a file
– mkdir – Make a directory
– mount – Mount a file system
5/29/2016
COP4610
54
File Management System Calls
–
–
–
–
–
–
open – Open a file for reading or writing
creat – Create a new file and open it
readAn– open
Readfile
bytes
from anobject
openthat
filecan provide bytes
is a dynamic
write
– Write
an open
from
a file orbytes
accepttobytes
to be file
stored in the file. It has
a set
attributes,
file pointer. It is a virtual
close
– Close
an such
openasfile
device created by the operating system.
seek – Change the location in the open file of the
are passive containers of data
nextFiles
readhowever
or write
– stat – Get information about a file
– mkdir – Make a directory
– mount – Mount a file system
5/29/2016
COP4610
55
I/O System Calls
–
–
–
–
–
open – Open a device for reading or writing
read – Read bytes from an open device
write – Write bytes to an open device
close – Close an open device
ioctl – Control device
5/29/2016
COP4610
56
Communication System Calls
– pipe – Create an inter-process channel
– kill – Send a signal to a process or a group of
processes
– msgctl – Message control operations
– shmat, shmctl, shmget, shmop – Shared memory
operations
– Semctl, semget, semop – Semaphore operations
5/29/2016
COP4610
57
Information Maintenance System Calls
–
–
–
–
acct – Enable or disable process accounting
stime – Set system time and date
times – Get process and child process times
utimes – Set file times
5/29/2016
COP4610
58
Interactive and Programming Interfaces
• Interactive interfaces have advantages:
– for exploration
– for interactive use
• Programming interfaces have advantages :
– for detailed interactions
– Inter-application programming
– Scripting
• It is useful for a program to have both
interfaces
5/29/2016
COP4610
59
Examples
• Shell
– Interactive interface to OS
• System calls
– Programming interface to OS
5/29/2016
COP4610
60
Shell as an Interactive Interface
• Interactive access to the OS system calls and
system and user programs
– cd to change current working directory
• System call is chdir
– Started by the system for a user
• Contains a simple programming language
• Popularized by UNIX
– Bourne shell, C shell (csh), Korn shell (ksh),
Bourne-again shell (bash), etc.
5/29/2016
COP4610
61
Two views of a shell
5/29/2016
COP4610
62
Summary
• Operating system is the system software that
controls the basic operation of a computer
– The layer between the hardware and the user programs
– Resource manager: manage hardware and software
resources
– Goals of operating systems
• Convenience for users by providing a wide range of functions
• Efficient operation of the computer system
• Operating system provides services to user
programs through system calls
– Shell as an interactive interface to system calls and
system and user programs
5/29/2016
COP4610
63
Download