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

Functions of OS

The document provides an overview of operating systems, including their functions, structure, operations, and services. It discusses topics like computer system organization, memory management, storage management, protection and security, and more. The document is intended to teach the basic concepts and components of operating systems.

Uploaded by

Gethzi Akila
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Functions of OS

The document provides an overview of operating systems, including their functions, structure, operations, and services. It discusses topics like computer system organization, memory management, storage management, protection and security, and more. The document is intended to teach the basic concepts and components of operating systems.

Uploaded by

Gethzi Akila
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 63

Operating System –Class IV

UNIT I
UNIT I OPERATING SYSTEM OVERVIEW 7
Computer System Overview-Basic Elements, Instruction Execution,
Interrupts, Memory Hierarchy, Cache Memory, Direct Memory Access,
Multiprocessor and Multicore Organization.
Operating system overview-objectives and functions, Evolution of
Operating System. - Computer System Organization Operating System
Structure and Operations- System Calls, System Programs, OS
Generation and System Boot.
DMA
What is OS?
• Acts as an intermediary between user and computer hardware.

• A program that manages a computer’s hardware.


Functions of Operating System
• Process Management
• I/O Management
• Memory Management
• Storage Management
• Protection and security
• Computing environments
Computer System Organization
• Computer-system operation
• One or more CPUs, device controllers connect through common bus
providing access to shared memory
• Concurrent execution of CPUs and devices competing for memory cycles
Computer-System Operation
• I/O devices and the CPU can execute concurrently
• Each device controller is in charge of a particular device
type
• Each device controller has a local buffer
• CPU moves data from/to main memory to/from local
buffers
• I/O is from the device to local buffer of controller
• Device controller informs CPU that it has finished its
operation by causing an interrupt
How a Modern Computer Works

A von Neumann architecture


Computer-System Architecture

• Most systems use a single general-purpose processor


• Most systems have special-purpose processors as well
• Multiprocessors systems growing in use and importance
• Also known as parallel systems, tightly-coupled systems
• Advantages include:
1. Increased throughput
2. Economy of scale
3. Increased reliability – graceful degradation or fault tolerance
• Two types:
1. Asymmetric Multiprocessing – each processor is assigned a specie task.
2. Symmetric Multiprocessing – each processor performs all tasks
Symmetric Multiprocessing Architecture
Clustered Systems

• Like multiprocessor systems, but multiple systems working together


• Usually sharing storage via a storage-area network (SAN)
• Provides a high-availability service which survives failures
• Asymmetric clustering has one machine in hot-standby mode
• Symmetric clustering has multiple nodes running applications, monitoring each other
• Some clusters are for high-performance computing (HPC)
• Applications must be written to use parallelization
• Some have distributed lock manager (DLM) to avoid conflicting operations
Clustered Systems
Operating-System Structures
• Operating system services
• Various ways of structuring an OS
• System calls.
Operating-System Operations
• Interrupt driven (hardware and software)
• Hardware interrupt by one of the devices
• Software interrupt (exception or trap):
• Software error (e.g., division by zero)
• Request for operating system service
• Other process problems include infinite loop, processes modifying each
other or the operating system
Operating-System Operations (cont.)

• Dual-mode operation allows OS to protect itself and other


system components
• User mode and kernel mode
• Mode bit provided by hardware
• Provides ability to distinguish when system is running user code or kernel code
• Some instructions designated as privileged, only executable in kernel mode
• System call changes mode to kernel, return from call resets it to user
• Increasingly CPUs support multi-mode operations
• i.e. virtual machine manager (VMM) mode for guest VMs
Transition from User to Kernel Mode
• Timer to prevent infinite loop / process hogging resources
• Timer is set to interrupt the computer after some time period
• Keep a counter that is decremented by the physical clock.
• Operating system set the counter (privileged instruction)
• When counter zero generate an interrupt
• Set up before scheduling process to regain control or terminate program
that exceeds allotted time
Process Management
• A process is a program in execution. It is a unit of work within the system.
Program is a passive entity, process is an active entity.
• Process needs resources to accomplish its task
• CPU, memory, I/O, files
• Initialization data
• Process termination requires reclaim of any reusable resources
• Single-threaded process has one program counter specifying location of next
instruction to execute
• Process executes instructions sequentially, one at a time, until completion
• Multi-threaded process has one program counter per thread
• Typically system has many processes, some user, some operating system
running concurrently on one or more CPUs
• Concurrency by multiplexing the CPUs among the processes / threads
Process Management Activities
The operating system is responsible for the following activities in connection
with process management:

• Creating and deleting both user and system processes


• Suspending and resuming processes
• Providing mechanisms for process synchronization
• Providing mechanisms for process communication
• Providing mechanisms for deadlock handling
Memory Management

• To execute a program all (or part) of the instructions must be in


memory
• All (or part) of the data that is needed by the program must be in
memory.
• Memory management determines what is in memory and when
• Optimizing CPU utilization and computer response to users
• Memory management activities
• Keeping track of which parts of memory are currently being used and by
whom
• Deciding which processes (or parts thereof) and data to move into and out
of memory
• Allocating and deallocating memory space as needed
Storage Management
• OS provides uniform, logical view of information storage
• Abstracts physical properties to logical storage unit - file
• Each medium is controlled by device (i.e., disk drive, tape drive)
• Varying properties include access speed, capacity, data-transfer rate, access
method (sequential or random)

• File-System management
• Files usually organized into directories
• Access control on most systems to determine who can access what
• OS activities include
• Creating and deleting files and directories
• Primitives to manipulate files and directories
• Mapping files onto secondary storage
• Backup files onto stable (non-volatile) storage media
Mass-Storage Management
• Usually disks used to store data that does not fit in main memory or data
that must be kept for a “long” period of time
• Proper management is of central importance
• Entire speed of computer operation hinges on disk subsystem and its
algorithms
• OS activities
• Free-space management
• Storage allocation
• Disk scheduling
• Some storage need not be fast
• Tertiary storage includes optical storage, magnetic tape
• Still must be managed – by OS or applications
• Varies between WORM (write-once, read-many-times) and RW (read-write)
Performance of Various Levels of Storage

Movement between levels of storage hierarchy can be explicit or implicit


Migration of data “A” from Disk to Register

• Multitasking environments must be careful to use most recent value,


no matter where it is stored in the storage hierarchy

• Multiprocessor environment must provide cache coherency in


hardware such that all CPUs have the most recent value in their cache
• Distributed environment situation even more complex
• Several copies of a datum can exist
I/O Subsystem
• One purpose of OS is to hide peculiarities of hardware devices
from the user
• I/O subsystem responsible for
• Memory management of I/O including buffering (storing data
temporarily while it is being transferred), caching (storing parts of data
in faster storage for performance), spooling (the overlapping of output
of one job with input of other jobs)
• General device-driver interface
• Drivers for specific hardware devices
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
Operating System Services
• Operating systems provide an environment for execution of programs and services to programs and users
• 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
Operating System Services (Cont.)
• One set of operating-system services provides functions that are helpful to the user (Cont.):
• File-system manipulation - The file system is of particular interest. Programs need to read and write files and
directories, create and delete them, search them, list file Information, permission management.
• 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 to ensure correct and consistent computing
• Debugging facilities can greatly enhance the user’s and programmer’s abilities to efficiently use the
system
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 - CPU cycles, main memory, file storage, I/O devices.
• 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 multiuser 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
A View of Operating System Services
User Operating System Interface - CLI

CLI or command interpreter 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
Bourne Shell Command Interpreter
User Operating System Interface - GUI

• User-friendly desktop metaphor 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
• Many systems now include both CLI and GUI interfaces
• Microsoft Windows is GUI with CLI “command” shell
• Apple Mac OS X is “Aqua” GUI interface with UNIX kernel underneath and
shells available
• Unix and Linux have CLI with optional GUI interfaces (CDE, KDE, GNOME)
Touchscreen Interfaces

Touchscreen devices require new


interfaces
 Mouse not possible or not desired
 Actions and selection based on gestures
 Virtual keyboard for text entry
 Voice commands.
The Mac OS X GUI
System Calls
• Programming interface to the services provided by the OS
• Typically written in a high-level language (C or C++)
• Mostly accessed by programs via a high-level Application
Programming Interface (API) rather than direct system call use
• 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)
Note that the system-call names used throughout this text are generic
System Call
• Way for a user program to interface with the operating system

• A system call is a method for a computer program to request a service


from the kernel of the operating system on which it is running.
• Mostly accessed by programs via a high- level Application
Programming Interface (API) rather than direct system call
• Kernel is the essential center of a computer operating system (OS).
• It is the core that provides basic services for all other parts of the OS.
• It is the main layer between the OS and hardware.
• Helps with process and memory management, file systems, device control and
networking.
System Calls Vs User function
How a system call varies from a user function.
• A system call function may create and use kernel processes to execute
the asynchronous processing.
• A system call has greater authority than a standard subroutine. A
system call with kernel-mode privilege executes in the kernel
protection domain.
• The code and data for system calls are stored in global kernel
memory.
A View of Operating System Services
Example of System Calls
• System call sequence to copy the contents of one file to
another file
Example of Standard API
System Call Implementation
• Typically, a number is associated with each system call
– System-call interface maintains a table indexed according to
these numbers
• The system call interface invokes the intended system call in OS
kernel and returns status of the system call and any return
values
• The caller need not know a thing about how the system call is
implemented
– Just needs to obey the API and understand what the 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)
System Call -- OS Relationship
The handling of a user application invoking the open() system call
System Call Parameter Passing
• Three general methods used to pass parameters to the OS

1. Simplest: pass the parameters in registers


• In some cases, may be more parameters than registers
2. 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
3. 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
x points to a block of parameters. x is loaded into a register

Parameter Passing via Table


Types of System Calls
• System calls can be grouped roughly into six major
categories:
– Process control,
– File manipulation,
– Device manipulation,
– Information maintenance,
– Communications,
– Protection.
System Calls – Process Control
• create process, terminate process
• end, abort
• load, execute
• get process attributes, set process attributes
• wait for time
• wait event, signal event
• allocate and free memory
• Dump memory if error
• Debugger for determining bugs, single step execution
• Locks for managing access to shared data between
processes
System Calls – File
Management
• Create file
• Delete file
• Open and Close file
• Read, Write, Reposition
• Get and Set file attributes
System Calls – Device Management

• request device, release device


• read, write, reposition
• get device attributes, set device attributes
• logically attach or detach devices
System Calls -- Information Maintenance

• get time or date,


• set time or date
• get system data,
• set system data
• get and set process, file, or device attributes
System Calls – Communications
• create, delete communication connection
• if message passing model:
– send, receive message
• To host name or process name
• From client to server
• If shared-memory model:
– create and gain access to memory regions
• transfer status information
• attach and detach remote devices
System Calls -- Protection
• Control access to resources
• Get and set permissions
• Allow and deny user access
Examples of Windows and Unix System Calls
Example -- Standard C Library
C program invoking printf() library call, which calls write() system call
Program
• Program using fork, getpid, getppid system calls
• Programs using exec System calls
• Program using opendir, readdir, closedir system calls
• Program using stat system calls
• Programs using open and close system call
fork( )
• Used to create new processes.
• The new process consists of a copy of the address space of the
original process.
• The value of process id for the child process is zero.
• The value of process id for the parent is an integer value greater than
zero.
getpid( ) & getppid()
• getpid()
• Each process is identified by its id value.
• This function is used to get the id value of a particular process
• getppid()
• Used to get particular process parent‘s id value.
• perror()
• Indicate the process error
Sample Program
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int main() {
int forkStatus;
int pid;
int ppid;
forkStatus = fork();
/* Child... */
if(forkStatus == 0) {
printf("\n Child process:");
pid = getpid();
ppid = getppid();
printf("\nChild's Process id: %d",pid);
printf("\nParent's Process id: %d",ppid);
/* Parent... */
} else if (forkStatus != -1) {
printf("\n Parent process:");
pid=getpid();
printf("\nProcess id: %d",pid);
} else {
perror("Error while calling the fork function");
}
,/; ‗‘

.k
return 0;
}
Output
rit@rit-OptiPlex-3010:~/Documents$ gcc forktest.c
rit@rit-OptiPlex-3010:~/Documents$ ./a.out
Parent process:
Process id: 4177
Child process:
Child's Process id: 4178
Parent's Process id: 4177
wait() System Call
wait( )
• The parent waits for the child process to complete using the wait
system call.
• The wait system call returns the process identifier of a terminated
child, so that the parent can tell which of its children has terminated.
Syntax : wait( NULL)
exit( )

• A process terminates when it finishes executing its final statement


and asks the operating system to delete it by using the exit system
call.
• At that point, the process may return data (output) to its parent
process (via the wait system call).
exec system calls
• exec type system calls allow a process to run any program files,
which include a binary executable or a shell script .
• exec is used when the user wants to launch a new file or program in
the same process.

You might also like