Adapted from slides ©2005 Silberschatz, Galvin, and Gagne Lecture 4: Processes.
Introductiontawalbeh/nyit/csci620/slides/Introduction.pdf · Operating System Concepts – 7th...
Transcript of Introductiontawalbeh/nyit/csci620/slides/Introduction.pdf · Operating System Concepts – 7th...
Lecture1: IntroductionLecture1: Introduction
1.2 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 12, 2005
Term: Spring 2009
Instructor: Dr. Lo’ai Tawalbeh
Email: [email protected]
Class: Wed 6:00 pm- 9:00 pm – Amman’s Campus
Prerequisites:
CSCI 370 -- Introduction to Computer Networks
ITEC 385 -- Introduction to Computer and Network Security or Equivalents.
See syllabus for other important info:
Exams
Attendance
Text and References
1.3 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 12, 2005
What is an Operating System?What is an Operating System?
A program that acts as an intermediary between a user of a computer and the computer hardware.
Operating system goals:
Execute user programs and make solving user problems easier (Provide an environment in which a user can execute programs in a convenient and efficient manner).
Manage the computer hardware in such a way as to ensure correct operation of the computer system and preventuser programs from interfering with the proper operation of the system.
1.4 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 12, 2005
Computer System StructureComputer System Structure
Computer system can be divided into four components
Hardware – provides basic computing resources
CPU, memory, I/O devices
Operating system
Controls and coordinates use of hardware among various applications and users
Application programs – define the ways in which the system resources are used to solve the computing problems of the users
Word processors, compilers, web browsers, database systems, video games
Users
People, machines, other computers
1.5 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 12, 2005
Four Components of a Computer SystemFour Components of a Computer System
1.6 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 12, 2005
Operating System DefinitionOperating System Definition
OS is a resource allocator
Manages all resources
Decides between conflicting requests for efficient and fair resource use
OS is a control program
Controls execution of programs to prevent errors and improper use of the computer
No universally accepted definition.
“Everything a vendor ships when you order the operating system” is one definition.
“The one program running at all times on the computer” is the one generally used in this course.
This is the kernel.
Everything else is either a system program (ships with the operating system) or an application program.
1.7 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 12, 2005
Multiprogrammed SystemsMultiprogramming needed for efficiency
Single user cannot keep CPU and I/O devices busy at all times
Multiprogramming organizes jobs (code and data) so CPU always has one to execute (increase CPU utilization).
Idea: a subset of total jobs in system is kept in memory
One job selected and run via job scheduling
When it has to wait (for I/O for example), OS switches to another job
OS Features Needed for Multiprogramming
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.
1.8 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 12, 2005
Memory Layout for Multiprogrammed SystemMemory Layout for Multiprogrammed System
1.9 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 12, 2005
Timesharing System (Interactive Systems)Timesharing System (Interactive Systems)
Timesharing (multitasking) CPU switches between jobs so frequently that users can interact with each job while it is running, creating interactivecomputing
The jobs are kept in memory and on disk (the CPU is allocated to a job only if the job is in memory).
A job swapped in and out of memory to the disk.
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” from the user’s keyboard.
features:
Response time should be < 1 second
Each user has at least one program executing in memory process
If several jobs ready to run at the same time CPU scheduling
If processes don’t fit in memory, swapping moves them in and out to run
Virtual memory allows execution of processes not completely in memory
1.10 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 12, 2005
Parallel SystemsParallel Systems
Multiprocessor systems with more than on 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
1.11 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 12, 2005
Parallel Systems (Cont.)Parallel Systems (Cont.)
Symmetric multiprocessing (SMP)
Each processor runs and identical copy of the operating system.
Many processes can run at once without performance deterioration.
Most modern operating systems support SMP
Asymmetric multiprocessing
Each processor is assigned a specific task; master processor schedules and allocated work to slave processors.
More common in extremely large systems
1.12 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 12, 2005
Distributed SystemsDistributed 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, telephone lines, or wireless.
Advantages of distributed systems.
Resources Sharing
Computation speed up – load sharing
Reliability
Communications
Requires networking infrastructure.
Local area networks (LAN) or Wide area networks (WAN)
May be either client-server or peer-to-peer systems.
1.13 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 12, 2005
RealReal--Time SystemsTime 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.
Real-Time systems may be either hard or soft real-time.
Hard real-time:
Secondary storage limited or absent, data stored in short term memory, or read-only memory (ROM)
Conflicts with time-sharing systems, not supported by general-purpose operating systems.
Soft real-time
Limited utility in industrial control of robotics
Useful in applications (multimedia, virtual reality) requiring advanced operating-system features.
1.14 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 12, 2005
Hardware ProtectionHardware Protection
Protection is needed since:
Software error or request creates exception or trap
Division by zero, request for operating system service
Other process problems include infinite loop, processes modifying each other or the operating system
Dual-mode operation allows OS to protect itself and other system components from user processes (an incorrect program cannot cause other programs to execute incorrectly)
User mode: execution done on behalf of a user
kernel mode (also system mode or monitor mode): execution done on behalf of operating system.
1.15 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 12, 2005
DualDual--Mode OperationMode Operation
Mode bit added to computer hardware to indicate the current mode: kernel (0) or user (1).
Provides ability to distinguish when system is running user code or kernel code
Some instructions designated as privileged, only executable in kernel mode
When an interrupt or fault occurs hardware switches to kernel mode, return from the interrupt or fault switches to user mode
kernel user
Interrupt/fault
set user mode
1.16 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 12, 2005
Transition from User to Kernel ModeTransition from User to Kernel Mode
Timer used to prevent infinite loop / process hogging resources
Set interrupt after specific period
Operating system decrements counter
When counter zero generate an interrupt
Set up before scheduling process to regain control or terminate program that exceeds allotted time
1.17 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 12, 2005
I/O ProtectionI/O Protection
All I/O instructions are privileged instructions.
Must ensure that a user program could never gain control of the computer in kernel mode (I.e., a user program that, as part of its execution, stores a new address in the interrupt vector).
System calls are used to perform I/O. (later on system calls)
1.18 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 12, 2005
Memory ProtectionMemory Protection
In order to have memory protection, add two registers that determine the range of legal addresses a program may access:
Base register – holds the smallest legal physical memory address.
Limit register – contains the size of the range
Memory outside the defined range is protected.
1.19 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 12, 2005
Address ProtectionAddress Protection
When executing in kernel mode, the operating system has unrestricted access to both monitor and user’s memory.
The load instructions for the baseand limit registers are privileged instructions.
1.20 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 12, 2005
CPU ProtectionCPU Protection
Timer – interrupts computer after specified period to ensure operating system maintains control.
Timer is decremented every clock tick.
When timer reaches the value 0, an interrupt occurs.
Timer commonly used to implement time sharing.
Time also used to compute the current time.
Load-timer is a privileged instruction.
1.21 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 12, 2005
User Protection and SecurityUser Protection and Security
Protection – any mechanism for controlling access of processes or users to resources defined by the OS
Security – defense of the system against internal and external attacks
Huge range, including denial-of-service, worms, viruses, identity theft, theft of service
Systems generally first distinguish among users, to determine who can do what
User identities (user IDs, security IDs) include name and associated number, one per user
User ID then associated with all files, processes of that user to determine access control
Group identifier (group ID) allows set of users to be defined and controls managed, then also associated with each process, file
Privilege escalation allows user to change to effective ID with more rights
1.22 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 12, 2005
Operating System ServicesOperating System Services
One set of operating-system services provides functions that are helpful to the user:
User interface - Almost all operating systems have a user interface (UI)
Varies between Command-Line (CLI), Graphics User Interface (GUI), Batch
Program execution - The system must be able to load a program into memory and to run that program, end execution, either normally or abnormally (indicating error)
I/O operations - A running program may require I/O, which may involve a file or an I/O device.
File-system manipulation - The file system is of particular interest. Obviously, programs need to read and write files and directories, create and delete them, search them, list file Information, permission management.
1.23 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 12, 2005
Operating System Services (Cont.)Operating System Services (Cont.)
One set of operating-system services provides functions that are helpful to the user (Cont):
Communications – Processes may exchange information, on the same computer or between computers over a network
Communications may be via shared memory or through message passing (packets moved by the OS)
Error detection – OS needs to be constantly aware of possible errors
May occur in the CPU and memory hardware, in I/O devices, in user program
For each type of error, OS should take the appropriate action toensure correct and consistent computing
Debugging facilities can greatly enhance the user’s and programmer’s abilities to efficiently use the system
1.24 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 12, 2005
Operating System Services (Cont.)Operating System Services (Cont.)
Another set of OS functions exists for ensuring the efficient operation of the system itself via resource sharing
Resource allocation - When multiple users or multiple jobs running concurrently, resources must be allocated to each of them
Many types of resources - Some (such as CPU cycles, main memory, and file storage) may have special allocation code, others (such as I/O devices) may have general request and release code.
Accounting - To keep track of which users use how much and what kinds of computer resources
Protection and security - The owners of information stored in a multi-user or networked computer system may want to control use of that information, concurrent processes should not interfere with each other
Protection involves ensuring that all access to system resources is controlled
Security of the system from outsiders requires user authentication, extends to defending external I/O devices from invalid access attempts
If a system is to be protected and secure, precautions must be instituted throughout it. A chain is only as strong as its weakest link.
1.25 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 12, 2005
User Interface User Interface -- CLICLI
Command Line Interface (CLI) allows direct command entry
Sometimes implemented in kernel, sometimes by systems program
Sometimes multiple flavors implemented – shells
Primarily fetches a command from user and executes it
– Sometimes commands built-in, sometimes just names of programs
» If the latter, adding new features doesn’t require shell modification
1.26 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 12, 2005
User Interface User Interface -- GUIGUI
User-friendly desktop metaphor or graphical interface
Usually mouse, keyboard, and monitor
Icons represent files, programs, actions, etc
Various mouse buttons over objects in the interface cause various actions (provide information, options, execute function,open directory (known as a folder)
Invented at Xerox PARC, become widespread through Apple.
Many systems now include both CLI and GUI interfaces
Microsoft Windows is GUI with CLI “command” shell
Solaris is CLI with optional GUI interfaces (Java Desktop, KDE)
1.27 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 12, 2005
System CallsSystem Calls
Programming interface to the services provided by the OS
Typically written in a high-level language (C or C++)
Some low-level tasks are written using assembly language.
Mostly accessed by programs via a high-level Application Program Interface (API) rather than direct system call use( or system call interface)
The API specifies a set of functions that are available for the programmer.
Three most common APIs are Win32 API for Windows, POSIX API for POSIX-based systems (including virtually all versions of UNIX, Linux, and Mac OS X), and Java API for the Java virtual machine (JVM)
Why use APIs rather than system calls?
Portability: the same API can run of different architectures.
Relief a programmer from the details and functionality of system calls.
1.28 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 12, 2005
Example of System CallsExample of System Calls
System call sequence to copy the contents of one file to anotherfile
1.29 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 12, 2005
System Call ImplementationSystem Call Implementation
Typically, a number associated with each system call
System-call interface maintains a table indexed according to these numbers
The system call interface invokes intended system call in OS kernel and returns status of the system call and any return values
The caller need know nothing about how the system call is implemented or how it works
Just needs to obey API and understand what OS will do as a result call
Most details of OS interface hidden from programmer by API
Managed by run-time support library (set of functions built into libraries included with compiler) through system calls interface
1.30 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 12, 2005
API API –– System Call System Call –– OS RelationshipOS Relationship
1.31 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 12, 2005
System Call Parameter PassingSystem Call Parameter Passing
Often, more information is required than simply identity of desired system call
Exact type and amount of information vary according to OS and call
Three general methods used to pass parameters to the OS
Simplest: pass the parameters in registers
In some cases, may be more parameters than registers
Parameters stored in a block, or table, in memory, and address of block passed as a parameter in a register
This approach taken by Linux and Solaris
Parameters placed, or pushed, onto the stack by the program and popped off the stack by the operating system
Block and stack methods do not limit the number or length of parameters being passed
1.32 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 12, 2005
Parameter Passing via TableParameter Passing via Table
1.33 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 12, 2005
Standard C Library ExampleStandard C Library Example
C program invoking printf() library call, which calls write() system call
1.34 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 12, 2005
Types of System CallsTypes of System Calls
Process control: end, abort, create, load, execute, wait (time, signal), get or set process attributes….etc
Single and multitask systems (DOS, FreeBSD)
File management: create, delete, open, close, read, write, attributes (permission, name, type)…
Device management: request, release, read, write…
Information maintenance: time, date, system info
Communications:
message passing: connection must be in existence
shared memory: agreement is needed, no protection.
Must insure that processes don’t write to the same location simultaneously.
End of Lecture 1End of Lecture 1