OS Components: Process Management

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 26

OS Components

• Process Management (Module 4)


– A program is a set of instructions
– A process is a program whose instructions are executed
• In some order
• Using some resources
– The task of the operating system is to
• Pass the instructions to the various hardware devices
• Provide input, output and memory for the process
– I do not mean RAM in the case of memory
• Allocate and manage the resources required:
– Partly statically when the process starts
– Partly dynamically at run-time
OS Components

• Process Management (cont’d)


– Processes can be either system or user.
• A system process has full access to the hardware
• A user process is managed.
– There is a strong move towards managing everything.
For example, Java defines a managed run-time virtual
machine. .NET also defines a managed virtual machine.
– Process management requires the
• Creation and deletion of user and system processes
• The suspension and resumption of processes
• Provision of mechanisms for synchronization
• Provision of mechanisms for process communication
• Provision of mechanisms for deadlock handling
OS Components
• Memory Management (Module 3)
– RAM is the “workspace” of processes
• It is the only storage device that the CPU can access for
– Instructions
– Temporary data storage (partial results)
– Processes are always loaded and executed in memory
• I don’t mean RAM.
– Normally, secondary storage is used
– The OS manages loading of required items into RAM for
CPU access
• Efficient use of the CPU requires that several processes be
loaded into memory at once
• The memory management scheme has a huge impact on the
effectiveness of the system.
OS Components
– In general, the operating system must:
• Keep track of which parts of RAM are being used and by
whom.
• Decide which processes are to be loaded into memory
• Decide which parts of memory must appear in RAM
• Allocate and deallocate memory space as needed.
OS Components

• Secondary Storage Management


– RAM is fast, but usually volatile and not sufficient to hold all the
processes required.
– There is a usually a slower, but larger persistent storage device.
– This is secondary storage, and is used as
• Virtual memory when memory is insufficient
• A persistent data store
– The operating system must manage:
• The free space on the secondary storage
• The storage and retrieval of data in the store
• Access scheduling of the data store
– Because it is slow
OS Components
• I/O Management
– The operating system is meant to hide the peculiarities of the
hardware from the programs.
• From a programmer’s perspective, there is no difference
accessing a file on a 200Gb SCSI drive than a 80Gb IDE drive
• Access to the drives is controlled by the I/O subsystem which
abstracts out the hardware via device drivers
– The device driver maps the functions required by the
system to the specific hardware.
– The I/O subsystem consists of
• A buffer-caching system
• A general device-driver interface
• Drivers for specific hardware devices
OS Components
• File Management (Module 5)
– This is one of the most visible components of the operating
system
• The user’s view of the system is usually based on the files
stored in secondary storage.
– Through the I/O subsystem, the operating system provides a
uniform logical view of the file system.
• Some operating systems, like UNIX take this further and
represent everything as a file.
– In general, the file sub-system is responsible for:
• Creating and deleting files
• Creating and deleting directories
• Supporting file and directory primitive operations
– read and write
• Mapping files to secondary storage
– Which bits of data go where?
OS Components
• Protection Sub-system
– Most modern operating systems allow multiple users and multiple
processes.
• There is a requirement to protect processes from the actions of
other processes.
• There is a concept from databases that is very applicable here
– Atomicity
– Consistency
– Isolation
– Durability
OS Components
• Protection Sub-system
– Consider that there are a finite number of resources.
• Each process should have fair access to those resources.
• They should be able to assume that they have exclusive use
of the resources.
– The only way to ensure this is for the operating system to
manage the resources.
OS Components

• Command-Interpreter
– The most important aspect of the operating system.
• This is the interface between the user and the operating
system itself so the users can make their wishes known.
– In some operating systems, this is built into the kernel.
– In others, such as MS-DOS (command.com) and UNIX (bash),
this is a special process that runs when the system starts up or
the user logs in.
– Recently, command interpreters have become very complex and
powerful
• The UNIX shell has a programming language built into it.
• The OS X interpreter is the windowing system.
– To an extent, the same can be said of the Windows
explorer.
OS Services

• There are some services that operating systems may provide to the
programmer.
– These provide a convenient way to access resources
– It also allows the operating system to provide guarantees about
the resources
• Protection
• Efficiency
• These services are categorized into two broad groups:
– User services
– System services
OS Services

• User operating system services


– Program execution
• The system must be able to load a program into memory and
run it. The program must also be able to end its execution
normally (or abnormally)
• An example of this is the fork() system function in UNIX
– I/O Operations
• For protection, the operating system must provide these
services
• An example in UNIX is open()
– File-system manipulation
• The operating system needs to provide means for programs to
access the data in files stored in secondary storage.
OS Services
– Communication
• The operating system has to provide a means for processes to
communicate.
• Sharing information is essential at almost all levels.
• Typically the operating system provides several structures such as
message queues, shared memory or pipes to link processes
together.
– Error detection
• The operating system has to provide a means to detect and recover
(if possible) from errors.
• If recovery is possible, it should log the error and recover as
gracefully as possible
– Terminate the offending program
• If recovery is not possible, then it should halt the system to ensure
that there is no corruption of the system information
• An error should not cause the computer to crash
Error: A process has scribbled on memory outside its
memory segment.

AX: 120DA8F9
BX: 120DA8F9
SP: 120DA8F9
PC: 120DA8F9

This has happened because Windows does not have


secure memory protection.
OS Services
• System services
– Resource allocation
• The system must have a method for allocating resources.
– Some require special allocation code (CPU, file system,
memory)
– Some use generic lock-release allocation (modem)
– Accounting
• This is a ‘paper’ trail of what users do.
– In some instances, it is important to check what the users are
doing. For example, in a banking system.
• This also sometimes helps the operating system optimize its
performance (by accumulating statistics)
– Windows has a tracking service that optimizes file access by
moving popular files to the inner track of the disk.
– Protection
• Protection is the that each process executes in (apparent) isolation
from all other processes.
System functions and library functions

• A system function is executable code that is part of the kernel and


executes with full access to the hardware.
• Any other function (library or user defined) executes with the same
privileges as the user that owns the process.
– Controlled with hardware support to limit which areas of memory
and which machine instructions may be used.
– In the Intell CPU there is “User Mode” and “Real Mode” for this.
System code runs in “Real Mode”

• Need more work on this.


System Calls
• System calls are the mechanism in which processes interact with the
system.
• They are the programmer interface to the system
– They are usually assembly level instructions.
– However, most modern languages provide an API that replaces
these assembly level calls.
• The API usually abstracts the more useful high-level
functionality (e.g. fwrite() in Unix)
• They are so useful that almost nobody deals with the
assembly level system calls anymore.
– The system calls are arranged into five main categories.
• Process control
• File manipulation
• Device manipulation
• Information maintenance
• Communications
System Calls

• Process Control
– End or Abort a process
• Passing control back to the shell
• Or handling special abort conditions
• Reporting errors
– Create a process / submit job; Load and Execute a program
• Not as simple as just having the shell execute a program – as
there must be a mechanism for any process to load and
execute a program.
• Fork() system call in Unix is a method to create a new
process.
• Exec() system call in Unix is a method to cause the current
process to begin executing another program
• In batch systems, there must also be a way to submit the job
for processing.
System Calls
• Process Control
– Get and Set process attributes
• Such as priority of the process or maximum allowable
execution time.
– Wait for time, event or signal (OS must decide who gets the
signal)
• Timeouts on network connections
• Hardware event such as a mouse-click
• Software signal from a concurrent process.
– Trace and Dump
• Used for debugging purposes. These allow the system to
trace the current execution of a program; and dump the
contents of memory (and the process state).
System Calls

• File manipulation
– Create and delete a file
– Open and close a file
– Read, write and reposition the file pointer
– Get and Set file attributes
System Calls

• Device manipulation
– Request and release device
– Read, write and reposition
– Get and Set device attributes
– Attach and Detach devices
• USB
• Floppy
• Cdrom
System Calls

• Information maintenance
– Get and Set date / time
– Get and Set system data
– Get process, file or device attributes
– Set process, file or device attributes
System Calls

• Communications
– Create and delete communications channel
– Send and receive messages
– Transfer status information
– Attach or detach remote devices
System Programs

• System programs are programs that provide a convenient


environment for file operations and running programs.
• They are the user interface to the system.
– For example, although there is a system call to delete a file (in
Unix this is unlink()). In most cases, the system program rm is
used instead.
• The user’s view of the system is generally made up of the system
programs
– Intel systems all have the same system calls (since they all have
similar hardware)
– The system programs make up the operating environment – such
as Linux, MS-DOS, Windows.
• In GIU interfaces line MS XP, this functionality is coded into the
interface so explorer is the only system program.
System Structure

• Simple structure
– MS-DOS was an operating system with a simple structure.
• No separation between interfaces and levels of functionality.
– A program can access the hardware (RAM, Video Ram,
hard disk, etc. directly with its own machine code.
» No security
» DOS was unstable because of this
System Structure
• Layered Approach
– Most modern operating systems utilize a layered approach.
• Within each layer, there may also be several subsystems
• In theory, each layer can only access the layer above or below
it.
– User Programs
– Language API
– System Calls
– Hardware
• Each level provides some core service to the layer above it.
• DirectX provides a consistent API to game developer. It
consists of several subsystems (DirectPlay, DirectSound)

You might also like