0% found this document useful (0 votes)
168 views25 pages

Rtos Unit 1 Notes

Uploaded by

Aravind Aravind
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
168 views25 pages

Rtos Unit 1 Notes

Uploaded by

Aravind Aravind
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Chennai Institute Of Technology REAL TIME OPERATING SYSTEM ECE DEPARTMENT

Course Code REAL TIME OPERATING SYSTEMS L T P C

ECPE2X15 3 0 0 3

COURSE OBJECTIVES:
● To expose the students to the fundamentals of interaction of OS with a computer and
User computation.
● To teach the fundamental concepts of how process are created and controlled with OS.
● To study programming logic of modeling Process based on range of OS features.
● To compare types and Functionalities in commercial OS, application development using
RTOS.
● To involve Discussions/ Practice/Exercise onto revising & familiarizing the concepts
acquired.

UNIT I INTRODUCTION TO OPERATING SYSTEMS 9

Basic of Operating system – Evolution of operating system – Hardware review- Types of


Operating system - Operating system concepts - Systems calls – Operating system structure.

UNIT II PROCESSES AND THREADS 9

RTOS Architecture – RTOS Task and Task state, Process Synchronization, Message queues,
shared memory, Mail boxes, pipes, Critical section, Semaphores, mutex, priority inversion and
ceiling, circular and swinging buffers.

UNIT III TASK MANAGEMENT AND RTOS SCHEDULING 9

Process and Threads, Process Control Block, Process Attributes, Interrupt processing, memory
management, Priority based scheduling, Rate-Monotonic scheduling, Earliest Deadline first
scheduling

UNIT IV REALTIME KERNEL 9

Principles, Kernel, Monolithic and Microkernel, Design issues, Polled Loop Systems, RTOS
Porting to a Target, Comparison and Basic study of various RTOS like VX works Linux
supportive RTOS.

UNIT V FREE RTOS Concepts 9

Over view of Free RTOS – Architecture – Advanced Free RTOS concepts – Implementation of
Task Scheduling, Queue management, mutex, Semaphore with Free RTOS.

TOTAL : 45 PERIODS
Chennai Institute Of Technology REAL TIME OPERATING SYSTEM ECE DEPARTMENT

UNIT I INTRODUCTION TO OPERATING SYSTEMS

Topic 1: Basic of Operating system:


• An Operating system (OS) is a program that manages the computer hardware.
• It also provides a basis for Application programs and acts as an intermediary
between computer User and computer Hardware.

FIG.1

 Here we see the hardware at the bottom. The hardware consists of chips, boards,
disks, a keyboard, a monitor, and similar physical objects. On top of the hardware is
the software.
 Most computers have two modes of operation: kernel mode and user mode.
 The operating system, the most fundamental piece of software, runs in kernel mode
(also called supervisor mode).

FIG.2

• The User interface program Shell or GUI is the lowest level of user mode software.
Chennai Institute Of Technology REAL TIME OPERATING SYSTEM ECE DEPARTMENT

• The ultimate purpose of GUIs is to allow humans to interact with a device’s


underlying code by separating us from the technical details and presenting a
simplified interface to the user. This process is called Abstraction.

Main Function of OS:

• Providing Abstraction to User program


• Managing the computer Resources.

Basic Functions of an Operating System:

1. Process Management:
o Function: Manages the execution of processes, including task scheduling,
creation, termination, and synchronization.
o Example: Windows Task Manager allows users to view and manage running
processes.
2. Memory Management:
o Function: Manages the allocation and deallocation of memory space to
various programs to ensure efficient operation.
o Example: The use of virtual memory in operating systems like Windows and
Linux allows for more efficient memory usage.
3. File System Management:
o Function: Manages files on the storage devices, including file creation,
deletion, reading, writing, and permissions.
o Example: File Explorer in Windows provides a user interface to manage files
and directories.
4. Device Management:
o Function: Manages hardware devices by using device drivers to facilitate
communication between the OS and hardware.
o Example: Printers, keyboards, and network adapters are managed by the OS
to ensure they function correctly.
5. Security and Access Control:
o Function: Protects data and resources from unauthorized access and ensures
system security.
o Example: User authentication and permissions in Linux ensure that only
authorized users can access certain files and perform specific actions.
6. User Interface:
o Function: Provides a way for users to interact with the computer, either
through command-line interfaces (CLI) or graphical user interfaces (GUI).
o Example: The Windows desktop environment provides a GUI for easy
navigation and interaction with the system.

Working of Operating system:


Structure Of computer System is required to understand how operating system
works
Chennai Institute Of Technology REAL TIME OPERATING SYSTEM ECE DEPARTMENT

.
Fig.3
 A modern general purpose computer system consist of one or more CPU’s and a
number of device controllers connected through a common bus that provides access
to shared memory.
 Bootstrap Program : The initial program that runs when a computer is powered up or
Rebooted.
 Stored in ROM
 It must know the address of OS (Kernel) and how to load it and start executing that
system.
Interrupt :
• The occurrence of an even is usually signalled by an Interrupt from Hardware or
Software.
• Hardware may trigger an interrupt at any time by sending a signal to the CPU,
usually by the way of the system bus.
System Call :
• Software may trigger an interrupt by executing a special operation called system
call.

Topic 2: Evolution of operating system:


1. First generation: Vacuum tubes (1945-55)
 After Babbage’s efforts,. Professor John Atanasoff and his graduate student
Clifford Berry builtwhat is now regarded as the first functioning digital
computer at Iowa State University.
 It used 300 vacuum tubes. At roughly the same time, Konrad Zuse in Berlin
built the Z3 computer out of electromechanical relays.
 In 1944, the Colossus was built and programmed by a group of scientists
(including Alan Turing) at Bletchley Park, England, the Mark I was built by
Howard Aiken at Harvard, and the ENIAC was built by William Mauchley and
his graduate student J. Presper Eckert at the University of Pennsylvania.
 Some were binary, some used vacuum tubes, some were programmable, but
all were very primitive and took seconds to perform even the simplest
calculation.
Chennai Institute Of Technology REAL TIME OPERATING SYSTEM ECE DEPARTMENT

 In these early days, a single group of people (usually engineers) designed,


built, programmed, operated, and maintained each machine. All programming
was done in absolute machine language.
 Virtually all the problems were simple straight forward mathematical and
numerical calculations.

2. Second generations (1955-65): Transistors and Batch systems:


 Computers became reliable enough that they could be manufactured and sold to
paying customers with the expectation that they would continue to function long
enough to get some useful work done. For the first time, there was a clear
separation between designers, builders, operators, programmers, and
maintenance personnel.
 These machines, now called mainframes.
 Large second-generation computers were used mostly for scientific and
engineering calculations, such as solving the partial differential equations that
often occur in physics and engineering. They were largely programmed in
FORTRAN and assembly language. Typical operating systems were FMS
(the Fortran Monitor System) and IBSYS, IBM’s operating system for the
7094.

3.Third generations (1965-80) : ICs and Multiprogramming:

 Distinct Product Lines in Early 1960s:

 Large-scale scientific computers (e.g., IBM 7094) for numerical calculations.


 Commercial computers (e.g., IBM 1401) for tape sorting and printing.

 Challenges and IBM's Solution:

 Maintaining two incompatible product lines was costly.


 IBM introduced System/360 to unify the product lines.

 System/360:

 Software-compatible machines of varying sizes and capabilities.


 Unified architecture and instruction set.
 Designed for both scientific and commercial computing.

 Successors and Impact:

 IBM continued with backward-compatible successors: 370, 4300, 3080, 3090, and
zSeries.
 System/360 used integrated circuits, providing cost-performance advantages.
 Concept of compatible computer families adopted industry-wide.

 OS/360 Challenges:

 Required to work on all models, leading to complexity and numerous bugs.


Chennai Institute Of Technology REAL TIME OPERATING SYSTEM ECE DEPARTMENT

 Millions of lines of assembly language, written by thousands of programmers.


 Continuous need for new releases to fix bugs.

 Third-Generation Operating Systems:

 Multiprogramming to avoid CPU idleness.


 Spooling for efficient job management.

 Timesharing Systems:

 CTSS (first general-purpose timesharing system) developed at M.I.T.


 Popularized with the spread of necessary protection hardware.

 MULTICS:

 Ambitious timesharing system developed by M.I.T., Bell Labs, and General Electric.
 Introduced many seminal ideas despite limited commercial success.

 Cloud Computing Parallel:

 Modern cloud computing resembles the MULTICS vision of a computer utility.

 Minicomputers and UNIX:

 Growth of minicomputers like DEC PDP series.


 UNIX development by Ken Thompson at Bell Labs.
 IEEE POSIX standard for UNIX compatibility.

 MINIX and Linux:

 MINIX: Educational UNIX clone by Andrew S. Tanenbaum.


 Linux: Production version inspired by MINIX, developed by Linus Torvalds.

4.Fourth generation (1980) Personal Computers:

With the development of LSI (Large Scale Integration) circuits—chips containing thousands
of transistors on a square centimeter of silicon—the age of the personal computer dawned. In
terms of architecture, personal computers (initially called microcomputers) were not all
that different from minicomputers of the PDP-11 class, but in terms of price they
certainly were different.

1. Intel's Request for an OS:

 In 1974, Intel released the 8080, the first general-purpose 8-bit CPU.
 Intel needed an operating system for the 8080 to facilitate testing.
 Gary Kildall, a consultant for Intel, was tasked with writing the OS.
Chennai Institute Of Technology REAL TIME OPERATING SYSTEM ECE DEPARTMENT

2. Creation of CP/M:

 Kildall, along with a friend, developed a controller for Shugart Associates' 8-inch
floppy disk.
 They connected the floppy disk to the 8080, creating the first microcomputer with a
disk.
 Kildall wrote the CP/M (Control Program for Microcomputers), a disk-based
operating system.

3. Intel's Decision and Digital Research:

 Intel, skeptical about the future of disk-based microcomputers, granted Kildall the
rights to CP/M.
 Kildall founded Digital Research to develop and market CP/M further.

4. CP/M's Dominance:

 In 1977, CP/M was rewritten to be compatible with various microcomputers using


8080, Zilog Z80, and other CPUs.
 Numerous applications were developed for CP/M, leading it to dominate the
microcomputing world for about five years.

5. IBM's Search for an OS:

 In the early 1980s, IBM sought software for the IBM PC and contacted Bill Gates for
a BASIC interpreter and an operating system.
 Gates suggested IBM contact Digital Research. Kildall's refusal to meet IBM and the
legal complications led IBM to return to Gates.

6. MS-DOS Development:

 Gates acquired DOS from Seattle Computer Products for $75,000.


 Tim Paterson, the creator of DOS, was hired by Microsoft to modify it according to
IBM's needs.
 The revised system, named MS-DOS, became the dominant OS for IBM PCs.

7. MS-DOS's Market Strategy:

 Gates' strategic decision to sell MS-DOS to computer manufacturers for bundling


with hardware contributed significantly to its success.
 CP/M, sold to end-users directly, could not compete with MS-DOS's distribution
model.

8. Kildall's Legacy and CP/M's Decline:

 Kildall passed away unexpectedly, and CP/M's influence dwindled.


 By 1983, with the introduction of the IBM PC/AT using the Intel 80286 CPU, MS-
DOS was firmly established, and CP/M was nearly obsolete.
Chennai Institute Of Technology REAL TIME OPERATING SYSTEM ECE DEPARTMENT

9. Evolution and Competition:

 MS-DOS evolved with new versions and features, some inspired by UNIX.
 The development of GUIs by researchers like Doug Engelbart and their adoption by
companies like Apple and Microsoft transformed user interfaces.
 Microsoft's Windows initially ran on top of MS-DOS, later evolving into standalone
OS versions, influencing personal computing significantly.

5. Fifth generation (1990) Mobile computers:

1. Early Mobile Phones:


o 1946: The first real mobile phone, weighing 40 kilos, was created. It required
a car to be transported.
o 1970s: The first true handheld mobile phone, nicknamed "the brick," was
introduced, weighing approximately one kilogram.
2. Rise of Mobile Phones:
o Mobile phone penetration reached nearly 90% of the global population.
o Modern mobile phones now offer functionalities beyond voice calls, such as
email, web browsing, texting, gaming, and navigation.
3. Introduction of Smartphones:
o The concept of combining telephony and computing in a single device dates
back to the 1970s.
o Mid-1990s: Nokia released the N9000, the first real smartphone, which
combined a phone and a PDA.
o 1997: Ericsson coined the term "smartphone" with its GS88 "Penelope."
4. Smartphone Operating Systems Competition:
o Symbian OS: Dominated the market in the first decade, used by brands like
Samsung, Sony Ericsson, Motorola, and especially Nokia.
o RIM's BlackBerry OS: Introduced in 2002, gained popularity in the business
market.
o Apple's iOS: Released in 2007 with the first iPhone, started capturing
significant market share.
o Android: A Linux-based OS released by Google in 2008, quickly overtook
rivals to become the dominant smartphone OS.
5. Shifts in Market Dominance:
o Symbian's market share declined rapidly, leading Nokia to adopt Windows
Phone as its primary platform in 2011.
o Android's success was bolstered by its open-source nature and permissive
licensing, allowing manufacturers to customize it for their hardware.
o The large community of developers writing apps in Java further contributed to
Android's popularity.
6. Future Uncertainty:
o The smartphone OS market is highly competitive and constantly evolving.
o Despite Android's current dominance, the market dynamics can change
rapidly, with competitors striving to regain market share.
Chennai Institute Of Technology REAL TIME OPERATING SYSTEM ECE DEPARTMENT

Topic 3: Types Of Operating Sytem:


Operating systems (OS) vary widely in structure and functionality to accommodate different
computing environments and user needs. Understanding these types helps in choosing the
right OS for specific applications:

1. Single-User Operating Systems:


o Characteristics: Designed for use by a single user at a time. Examples
include most personal computer operating systems like Microsoft Windows
and macOS.
o Applications: Ideal for desktops, laptops, and devices where individual user
interaction is predominant. They provide a user-friendly interface and support
a wide range of applications.
2. Multi-User Operating Systems:
o Characteristics: Allow multiple users to access and use the system
simultaneously. These OSes manage resources efficiently to ensure fair access
and security.
o Applications: Commonly used in server environments, mainframes, and
shared computing resources where multiple users need concurrent access.
Examples include UNIX variants and modern server editions of Windows.
3. Real-Time Operating Systems (RTOS):
o Characteristics: Designed to process data and complete tasks within strict
time constraints. They prioritize deterministic behavior and are critical in
applications where timing is crucial, such as industrial automation, robotics,
and embedded systems.
o Applications: Used in systems requiring immediate response times and
precise control, such as medical devices, automotive systems, and aerospace
applications. Examples include VxWorks and QNX.
4. Batch Processing Operating Systems:
o Characteristics: Manage and execute jobs in batches without user interaction.
Jobs are collected, processed sequentially, and results are produced.
o Applications: Historically used in early mainframe environments for tasks
like payroll processing and batch data processing. Modern variants still find
use in automated data processing and batch job scheduling.
5. Distributed Operating Systems:
o Characteristics: Coordinate and manage multiple independent networked
computers as a single system. They provide transparency to users, allowing
access to resources across the network.
o Applications: Used in modern distributed computing environments, cloud
computing platforms, and peer-to-peer networks. Examples include Linux-
based clusters and distributed versions of Windows Server.
6. Embedded Operating Systems:
o Characteristics: Designed to operate within embedded systems with limited
resources (such as memory and processing power). They are optimized for
specific hardware and functionalities.
o Applications: Found in everyday devices like smartphones, digital cameras,
household appliances, and automotive electronics. Examples include Android
for mobile devices and Embedded Linux distributions.
7. Mobile Operating Systems:
Chennai Institute Of Technology REAL TIME OPERATING SYSTEM ECE DEPARTMENT

o Characteristics: Optimized for mobile devices like smartphones, tablets, and


wearables. They emphasize touch interfaces, mobility, and connectivity.
o Applications: Used in consumer electronics to provide mobile computing
capabilities and access to app stores. Examples include iOS (Apple), Android
(Google), and Windows Mobile.

Applications in Modern Computing:

 Customization: Different types of OSes cater to diverse user requirements, from


personal computing to industrial automation and mobile applications.
 Performance Optimization: RTOS and embedded OSes prioritize efficiency and
real-time responsiveness, ensuring optimal performance in constrained environments.
 Security and Management: Multi-user and distributed OSes offer robust security
features and centralized management capabilities for shared computing resources and
networked systems.
 Flexibility and Scalability: Operating systems like Linux and distributed OSes
support scalability across diverse hardware platforms and cloud infrastructures,
accommodating varying workloads and growth requirements.

Difference Between RTOS and Embedded OS:

Real-Time Operating Systems (RTOS):

 Characteristics:
o Designed for applications requiring precise and deterministic response times.
o Guarantees deadlines are met consistently, critical for mission-critical systems.
o Typically minimalistic kernels to reduce overhead and ensure fast response.
o Examples include VxWorks, QNX, and FreeRTOS.
 Applications:
o Used in industries like aerospace, automotive, medical devices, and industrial
automation.
o Tasks include control systems, robotics, process control, and real-time data
acquisition.

Embedded Operating Systems (OS):

 Characteristics:
o Optimized for resource-constrained embedded systems with limited memory
and processing power.
o Often tailored to specific hardware platforms, ensuring efficient utilization of
resources.
o Includes support for I/O handling, memory management, and device drivers.
o Examples include Embedded Linux distributions, Windows Embedded
Compact, and Android (for embedded systems).
 Applications:
o Found in diverse embedded devices such as smartphones, digital cameras,
consumer electronics, and IoT devices.
o Provides operating environments for various applications requiring reliability,
performance, and specific functionalities.
Chennai Institute Of Technology REAL TIME OPERATING SYSTEM ECE DEPARTMENT

Comparison:

 Scope of Use:
o RTOS focuses on real-time responsiveness and deterministic behavior, critical
for applications with strict timing requirements.
o Embedded OSes target a broad range of embedded systems, offering
flexibility and scalability across different hardware platforms and applications.
 Resource Management:
o RTOS emphasizes minimalism and efficient resource management to meet
real-time constraints.
o Embedded OSes optimize resource utilization and performance within the
constraints of embedded hardware.
 Development and Deployment:
o RTOS requires specialized knowledge in real-time computing and often
involves rigorous testing and certification processes.
o Embedded OSes support development with standard tools and frameworks,
accommodating diverse development environments and application domains.
 Key Differences:
o RTOS prioritizes deterministic behavior and real-time responsiveness,
ensuring tasks are completed within specific deadlines.
o Embedded OSes offer broader flexibility and support for various applications
beyond real-time constraints, leveraging general-purpose features and
ecosystem support.

Topic 4: Computer hardware review

Introduction:

 Definition of Computer Hardware: The physical components that make up a


computer system, including the central processing unit (CPU), memory, storage,
motherboard, input/output devices, and power supply.
 Context: Modern computer hardware has evolved significantly, with advancements
driving improvements in performance, efficiency, and user experience.
Chennai Institute Of Technology REAL TIME OPERATING SYSTEM ECE DEPARTMENT

Central Processing Unit (CPU):

 Function: The CPU is the brain of the computer, responsible for executing
instructions and processing data.
 Recent Advancements:
o Multicore Processors: CPUs now come with multiple cores, allowing for
parallel processing and multitasking.

 The next step, multithreading or hyperthreading, involves replicating control logic to


allow CPUs to manage multiple threads simultaneously, improving efficiency but not
providing true parallelism.
 This advancement impacts operating systems, which must manage threads as separate
CPUs, potentially leading to inefficient scheduling.
 Further progression includes multicore chips, with many processors on a single chip,
necessitating multiprocessor operating systems. GPUs, with thousands of tiny cores,
excel at parallel computations but are less suited for serial tasks and operating system
functions.

o Higher Clock Speeds and Advanced Architectures: Modern CPUs feature


increased clock speeds and improved microarchitectures (e.g., Intel's Alder
Lake, AMD's Zen 3).
 Impact: Enhanced performance, enabling the handling of more complex tasks and
applications simultaneously.

Memory:
Chennai Institute Of Technology REAL TIME OPERATING SYSTEM ECE DEPARTMENT

Cache memory:

 Cache memory, primarily managed by hardware, enhances performance by storing the


most frequently accessed data in a high-speed cache close to the CPU.
 Main memory is segmented into cache lines, typically 64 bytes each. A cache hit
occurs when a required memory word is found in the cache, providing rapid access in
about two clock cycles.
 Caching extends beyond RAM, optimizing performance across various computing
areas. Operating systems often cache frequently accessed files and paths to reduce
disk access and network lookups.
.
 Modern CPUs typically feature two cache levels: L1 (inside the CPU for immediate
access) and L2 (holding several megabytes of data with a slight access delay).
 In multicore chips, cache design varies, with Intel using a shared L2 cache and AMD
opting for separate L2 caches for each core, each approach having distinct advantages
and challenges.

Memory (RAM):

 Function: Random Access Memory (RAM) provides temporary storage for data and
instructions that the CPU needs to access quickly.
 Recent Advancements:
o Increased Capacity and Speed: Modern RAM modules offer higher
capacities (e.g., 32GB, 64GB) and faster speeds (e.g., DDR4, DDR5).
o Lower Latency and Power Consumption: Improvements in latency and
power efficiency (e.g., LPDDR4X for mobile devices).
 Impact: Faster data access and processing, improved multitasking capabilities, and
better performance for memory-intensive applications.

Storage Devices:

 Function: Storage devices retain data and software programs permanently or semi-
permanently.
 Recent Advancements:
o Solid-State Drives (SSDs): Faster read/write speeds and lower latency
compared to traditional Hard Disk Drives (HDDs).
o Non-Volatile Memory Express (NVMe): NVMe SSDs use PCIe interfaces
for even higher data transfer rates.
 Impact: Quicker boot times, faster file access, and overall enhanced system
responsiveness.

Graphics Processing Unit (GPU):

 Function: The GPU handles rendering of images, videos, and animations, and can be
used for parallel processing tasks.
 Recent Advancements:
Chennai Institute Of Technology REAL TIME OPERATING SYSTEM ECE DEPARTMENT

o Ray Tracing and AI Capabilities: Modern GPUs (e.g., NVIDIA's RTX


series, AMD's Radeon RX) support real-time ray tracing and AI-based
enhancements.
o Increased Memory and Bandwidth: Higher VRAM and memory bandwidth
for better performance in gaming and professional applications.
 Impact: Superior graphics quality, faster rendering times, and enhanced performance
for AI and machine learning tasks.

Input/Output Devices:

 Function: Input devices (e.g., keyboard, mouse) allow users to interact with the
computer, while output devices (e.g., monitors, printers) display results.
 Recent Advancements:
o High-Resolution Displays: 4K and 8K monitors with high refresh rates for
smoother visuals.
o Ergonomic and Wireless Peripherals: Improved design for user comfort and
convenience.
 Impact: Better user experience, enhanced productivity, and more immersive
interactions.

Topic 5: Operating System Concepts:

• Processes
• Address spaces (memory)
• Files

Processes :

• Processes is basically a Program in execution.


• Each Processes associated with its Address space (flash / RAM)
• Each Processes associated with set of resources and open files .
• All information about each processes have its own address space is stored in an
operating system table called Operating Table.
• The process-management system calls are those dealing with the creation and
termination (read & terminate system call) of processes.

Consider a typical example:

• Command interpreter : A process called the command interpreter or shell reads


commands from a terminal.
• The user has just typed a command requesting that a program be compiled. The shell
must now create a new process that will run the compiler. When that process
has finished the compilation, it executes a system call to terminate itself.

Child processes:
Chennai Institute Of Technology REAL TIME OPERATING SYSTEM ECE DEPARTMENT

• If a process can create one or more other processes and these processes in turn can
create child processes.


• Inter-process communication: Related processes that are cooperating to get some
job done often need to communicate with one another and synchronize their
activities. This communication is called inter-process communication.
• Release unused memory.
• The operating system sets an Alarm signal to the process.

For example: a process that is communicating with another process on a different


computer does so by sending messages to the remote process over a computer
network.

Address Spaces:

 Every computer utilizes main memory to execute programs. Simple operating systems
handle one program at a time, requiring memory swaps for additional programs.
 More advanced systems allow multiple programs in memory simultaneously,
necessitating protection mechanisms managed by the operating system to prevent
interference.
 An essential aspect of memory management is addressing the processes' address
spaces.
 Each process typically has a range of addresses it can use, which may exceed the main
memory capacity.
 Initially, processes with larger address spaces than available memory were
unsupported.
Chennai Institute Of Technology REAL TIME OPERATING SYSTEM ECE DEPARTMENT

 Modern systems use virtual memory, where the operating system shuttles parts of the
address space between main memory and disk, creating an abstraction that decouples
address space from physical memory size.
 This allows address spaces to be larger or smaller than physical memory.

Files:

• All operating systems is the file system.


• System calls are obviously needed to create files, remove files, read files, and write
files. Before a file can be read, it must be located on the disk and opened, and after
being read it should be closed, so calls are provided to do these things.
• Directory : To provide a place to keep files, most PC operating systems have the
concept of a directory as a way of grouping files together.
• Calls are also provided to put an existing file in a directory and to remove a file from
a directory.
• Directory entries may be either files or other directories.

• Every file within the directory hierarchy can be specified by giving its path
name from the top of the directory hierarchy, the root directory.
• From Fig, the path for file CS101 is /Faculty/Prof.Brown/Courses/CS101.
• The leading slash indicates that the path is absolute, that is, starting at the root
directory.
• At every instant, each process has a current working directory, in which path names
not beginning with a slash are looked for.

Example: in Fig. 1-14, if /Faculty/Prof.Brown were the working directory, use of


the path - Courses/CS101

• Processes can change their working directory by issuing a system call specifying the
new working directory.
• Before a file can be read or written, it must be opened, at which time the permissions
are checked.
Chennai Institute Of Technology REAL TIME OPERATING SYSTEM ECE DEPARTMENT

• If the access is permitted, the system returns a small integer called a file descriptor to
use in subsequent operations. If the access is prohibited, an error code is returned.
• Special files:
• Special files are provided in order to make I/O devices look like files. That way, they
can be read and written using the same system calls as are used for reading and
writing files.
• Two kinds of special files exist: block special files and character special files.
• Pipe :
• A pipe is a sort of pseudo-file that can be used to connect two processes, as shown in
Fig.

• If processes A and B wish to talk using a pipe, they must set it up in advance. When
process A wants to send data to process B, it writes on the pipe as though it were an
output file.
• In fact, the implementation of a pipe is very much like that of a file. Process B can
read the data by reading from the pipe as though it were an input file.

Topic 6: System Call:

We know that, operating systems have two main functions:

• Providing Abstractions to user programs and managing the computer’s resources.


• For the most part, the interaction between user programs and the operating system
deals with the - - creating, writing, reading, and deleting files.
• The resource-management part is largely transparent to the users and done
automatically by operating system.
• Thus, the interface between user programs and the operating system is
primarily about dealing with the abstractions.
• The system calls available in the interface vary from one operating system to another.
• Since the actual mechanics of issuing a system call are highly machine dependent and
often must be expressed in assembly code.
• A procedure library is provided to make it possible to make system calls from C
programs and often from other languages as well.
• If a process is running a user program in user mode and needs a system service, such
as reading data from a file, it has to execute a trap instruction to transfer control to the
operating system.
• The operating system then figures out what the calling process wants by inspecting
the parameters.
• Then it carries out the system call and returns control to the instruction
following the system call.
Chennai Institute Of Technology REAL TIME OPERATING SYSTEM ECE DEPARTMENT

• Control switches from user mode to kernel mode to access the resource to execute the
process through TRAP instruction.
• System call is the programmatic way in which a computer program requests a service
from the kernel of the operating system.

Example:

Read system call:

count = read(fd, &buffer, nbytes);

• It has three parameters:

1. Specifying the file,


2. Pointing to the buffer (address of the buffer)
3. Giving the number of bytes to read.

• The system call (and the library procedure) return the number of bytes actually
read in count.
• If the system call cannot be carried out owing to an invalid parameter or a disk error,
count is set to −1.

• Calling the read library procedure, which actually makes the read system call,
• Step 1 to 3 : The calling program first pushes the parameters( file, address of buffer,
no of bytes) onto the stack.

The first and third parameters are called by value, but the second parameter is passed
by reference, meaning that the address of the buffer (indicated by &) is passed, not the
contents of the buffer.
Chennai Institute Of Technology REAL TIME OPERATING SYSTEM ECE DEPARTMENT

• Step 4 : This instruction is the normal procedure-call instruction used to call all
procedures.
• Step 5 : The library procedure, possibly written in assembly language, typically
puts the system-call number in a place where the operating system expects it, such as
a Register.
• step 6 : Then it executes a TRAP instruction to switch from user mode to kernel mode
and start execution at a fixed address within the kernel.
• Step 7 : The kernel code that starts following the TRAP examines the system-call
number and then dispatches to the correct system-call handler, usually via a
table of
• pointers to system-call handlers indexed on system-call number.
• Step 8: At that point the system-call handler runs.
• Step 9: Once it has completed its work, control
• may be returned to the user-space library procedure at the instruction following the
TRAP instruction .
• Step 10: This procedure then returns to the user program in the usual way procedure
calls return .
• Step 11: To finish the job, the user program has to clean up the stack, as it does after
any procedure call .

Topic 7: TYPES OF SYSTEM CALL:

• Process management
• File management
• Directory management
• Miscellaneous system calls

Process management:

Purpose: Create process , terminate process & wait

 fork() : pid = fork( ): It creates an exact duplicate of the original


process,(creates child process from parent).
 At the time of the fork, the parent’s data are copied to create the child,
subsequent changes in one of them do not affect the other one.
 The fork call returns a value, which is zero in the child and equal to the child’s PID
(Process IDentifier)in the parent. Using the returned PID, the two processes can see
which one is the parent process and which one is the child process.

 waitpid (): pid = waitpid(pid, &statloc, options):

• To wait for the child to finish, the parent executes a waitpid system call, which just
waits until the child terminates.
Chennai Institute Of Technology REAL TIME OPERATING SYSTEM ECE DEPARTMENT

• It reads a command from the terminal , waits for the child to execute the
command, and then reads the next command when the child terminates.
• waitpid(pid, &statloc, options): It has three parameters.

Pid = -1 indicates wait for child

&statloc = status indicates exit status

File management:

purpose : create file, delete file open ,close , read, and write .

To read or write a file, it must first be opened. This call specifies the file name to be
opened, either as an absolute path name or relative to the working directory,

O RDONLY -- open for reading

O WRONLY -- open for writing

O RDWR -- open for both

O CREAT -- create a new file

Directory management:

purpose : create and remove

 mkdir -- create empty directories


 rmdir -- remove empty directories,
 link -- Its purpose is to allow the same file to appear under two or more names,
often in different directories.

s = link(name1, name2).

Miscellaneous system calls:

 chdir call --- changes the current working directory. After the call
chdir("/usr/ast/test");

an open on the file xyz will open /usr/ast/test/xyz.

The concept of a working directory eliminates the need for typing (long) absolute path
names all the time.

 chmod system call chmod("file", 0644) :

makes it possible to change the mode of a file. For example, to make a file read only by
everyone except the owner, one could execute.
Chennai Institute Of Technology REAL TIME OPERATING SYSTEM ECE DEPARTMENT
Chennai Institute Of Technology REAL TIME OPERATING SYSTEM ECE DEPARTMENT

Topic 8 : Structure of operating system:

1. Monolithic systems.
2. Layered systems.
3. Microkernels.
4. Client – server model.
5. Virtual machines.

Monolithic systems:

• In the monolithic approach the entire operating system runs as a single


program in kernel mode.
• The operating system is written as a collection of procedures, linked
together into a single large executable binary program.
• When this technique is used, each procedure in the system is free to call
any other one.
• To construct the actual object program of the operating system when this
approach is used, one first compiles all the individual procedures
(or the files containing the procedures) and then binds them all
together into a single executable file using the system linker.
• Even in monolithic systems, however, it is possible to have some
structure. The services (system calls) provided by the operating system
are requested by putting the parameters in a well-defined place (e.g., on
the stack) and then executing a trap instruction.
• This instruction switches the machine from user mode to kernel mode and
transfers control to the operating system,
• The operating system then fetches the parameters and determines which
system call is to be carried out. After that, it indexes into a table that
contains in slot k a pointer to the procedure that carries out system call k.
• This organization suggests a basic structure for the operating system:

1. A main program that invokes the requested service procedure.

2. A set of service procedures that carry out the system calls.

3. A set of utility procedures that help the service procedures.


Chennai Institute Of Technology REAL TIME OPERATING SYSTEM ECE DEPARTMENT

• In addition to the core operating system that is loaded when the computer
is booted, many operating systems support loadable extensions, such
as I/O device drivers and file systems.
• These components are loaded on demand. In UNIX they are called
shared libraries.
• In Windows they are called DLLs (Dynamic-Link Libraries).

Layered systems:

Layer 0: Dealt with allocation of the processor, switching between


processes when interrupts occurred or timers expired.
Layer 0 provided the basic multiprogramming of the CPU.
Layer 1 :Layer 1 did the memory management. It allocated space for
processes in main memory and on a 512K word drum used for holding
parts of processes (pages) for which there was no room in main memory.
Layer 2 handled communication between each process and the operator
console (that is, the user). On top of this layer each process effectively
had its own operator console.
Layer 3 took care of managing the I/O devices and buffering the
information streams to and from them. Above layer 3 each process could
Chennai Institute Of Technology REAL TIME OPERATING SYSTEM ECE DEPARTMENT

deal with abstract I/O devices with nice properties, instead of real devices
with many peculiarities.
Layer 4 was where the user programs were found. They did not have to
worry about process, memory, console, or I/O management.
The system operator process was located in layer 5.
Example : the layering concept was present in the MULTICS system.

Microkernels:
• With the layered approach, the designers have a choice where to draw the
kernel-user boundary.
• Traditionally, all the layers went in the kernel, but that is not
necessary.
• In fact, a strong case can be made for putting as little as possible in kernel
mode because bugs in the kernel can bring down the system instantly.
• In contrast, user processes can be set up to have less power so that a bug
there may not be fatal.
• A monolithic operating system of five million lines of code is likely to
contain between 10,000 and 50,000 kernel bugs.
• The basic idea behind the microkernel design is to achieve high reliability
by splitting the operating system up into small, well-defined
modules, only one of which—the microkernel—runs in kernel mode
and the rest run as relatively power less ordinary user processes.
• In particular, by running each device driver and file system as a separate
user process, a bug in one of these can crash that component, but cannot
crash the entire system.
• Thus a bug in the audio driver will cause the sound to be garbled or
stop, but will not crash the computer.
• In contrast, in a monolithic system with all the drivers in the kernel, a
buggy audio driver can easily reference an invalid memory address
and bring the system to a grinding halt instantly
• A few of the better-known microkernels include Integrity, K42, L4,
PikeOS, QNX, Symbian, and MINIX 3.
• The MINIX 3 microkernel is only about 12,000 lines of C and some 1400
lines of assembler for very low-level functions such as catching interrupts
and switching processes.
• The C code manages and schedules processes, handles interprocess
communication (by passing messages between processes), and offers a set
of about 40 kernel calls to allow the rest of the operating system to do its
work.
Chennai Institute Of Technology REAL TIME OPERATING SYSTEM ECE DEPARTMENT

• These calls perform functions like hooking handlers to interrupts,


moving data between address spaces, and installing memory maps for
new processes.
• The process structure of MINIX 3 is shown in Fig. 1-26, with the kernel
call handlers labeled Sys.

 The device driver for the clock is also in the kernel because the
scheduler interacts closely with it. The other device drivers run as
separate user processes.

You might also like