Module 5
Module 5
Module 5
What Is OS ?
An Operating System (OS) is an interface between computer user and computer hardware. An operating system
is software which performs all the basic tasks like file management, memory management, process
management, handling input and output, and controlling peripheral devices such as disk drives and printers.
Some popular Operating Systems include Linux Operating System, Windows Operating System, VMS, OS/400,
AIX, z/OS, etc.
Definition:
An operating system is a program that acts as an interface between the user and the computer hardware and
controls the execution of all kinds of programs.
Page 1
RTOS AND IDE FOR ESD MODULE-5
An Operating System provides services to both the users and to the programs. It provides programs an
environment to execute.
Following are a few common services provided by an operating system: Program execution
I/O operations
Communication
Error Detection
Resource Allocation
Protection
Page 2
RTOS AND IDE FOR ESD MODULE-5
large array of words or bytes ranging in size from hundreds of thousand to billions. Main
memory stores the quickly accessible data shared by the CPU & I/O device. The central
processor reads instruction from main memory during instruction fetch cycle & it both reads
&writes data from main memory during the data fetch cycle. The main memory is generally the
only large storage device that the CPU is able to address & access directly. For example, for the
CPU to process data from disk. Those data must first be transferred to main memory by CPU
generated E/O calls. Instruction must be in memory for the CPU to execute them. The OS is
responsible for the following activities in connection with memory management.
Keeping track of which parts of memory are currently being used & by whom.
Deciding which processes are to be loaded into memory when memory space becomes
available.
Allocating &deal locating memory space as needed.
3. File Management:
File management is one of the most important components of an OS computer can store
information on several different types of physical media magnetic tape, magnetic disk & optical
disk are the most common media. Each medium is controlled by a device such as disk drive or
tape drive those has unique characteristics. These characteristics include access speed, capacity,
data transfer rate & access method (sequential or random).For convenient use of computer
system the OS provides a uniform logical view of information storage. The OS abstracts from
the physical properties of its storage devices to define a logical storage unit the file. A file is
collection of related information defined by its creator. The OS is responsible for the following
activities of file management.
Creating & deleting files.
Creating & deleting directories.
Supporting primitives for manipulating files & directories.
Mapping files into secondary storage.
Backing up files on non-volatile media.
4. I/O System Management:
One of the purposes of an OS is to hide the peculiarities of specific hardware devices from the
user. For example, in UNIX the peculiarities of I/O devices are hidden from the bulk of the OS
itself by the I/O subsystem. The I/O subsystem consists of:
A memory management component that includes buffering, catching & spooling.
Page 3
RTOS AND IDE FOR ESD MODULE-5
A general device- driver interfaces drivers for specific hardware devices. Only the device
driver knows the peculiarities of the specific device to which it is assigned.
Page 4
RTOS AND IDE FOR ESD MODULE-5
Page 5
RTOS AND IDE FOR ESD MODULE-5
• Problem: applications can e.g. – trash OS software. – trash another application. – hoard CPU time. –
abuse I/O devices. – Etc.
Page 6
RTOS AND IDE FOR ESD MODULE-5
Alternative structure: – push some OS services into servers. – servers may be privileged (i.e.
operate in kernel mode).
• Still access kernel via system calls, but need new way to access servers: ⇒ inter-process
Page 7
RTOS AND IDE FOR ESD MODULE-5
Real time system is used when there are rigid time requirements on the operation of a processor or
flow of data. Sensors bring data to the computers. The computer analyzes data and adjusts controls to
modify the sensors inputs. System that controls scientific experiments, medical imaging systems and
some display systems are real time systems. The disadvantages of real time system are: a. A real time
system is considered to function correctly only if it returns the correct result within the time constraints.
b. Secondary storage is limited or missing instead data is usually stored in short term memory or ROM. c.
Advanced OS features are absent. Real time system is of two types such as
• Hard real time systems: It guarantees that the critical task has been completed on time. The sudden
task is takes place at a sudden instant of time.
• Soft real time systems: It is a less restrictive type of real time system where a critical task gets priority
over other tasks and retains that priority until it computes. These have more limited utility than hard
real time systems. Missing an occasional deadline is acceptable e.g. QNX, VX works. Digital audio or
multimedia is included in this category. It is a special purpose OS in which there are rigid time
requirements on the operation of a processor. A real time OS has well defined fixed time constraints.
Processing must be done within the time constraint or the system will fail. A real time system is said to
function correctly only if it returns the correct result within the time constraint. These systems are
characterized by having time as a key parameter.
Task :
Task is a piece of code or program that is separate from another task and can be
executed independently of the other tasks.
In embedded systems, the operating system has to deal with a limited number of
tasks depending on the functionality to be implemented in the embedded system.
Page 8
RTOS AND IDE FOR ESD MODULE-5
Multiple tasks are not executed at the same time instead they are executed in
pseudo parallel i.e. the tasks execute in turns as the use the processor.
From a multitasking point of view, executing multiple tasks is like a single book
being read by multiple people, at a time only one person can read it and then take
turns to read it.
Different bookmarks may be used to help a reader identify where to resume reading
next time.
An Operating System decides which task to execute in case there are multiple tasks
to be executed. The operating system maintains information about every task and
information about the state of each task.
The information about a task is recorded in a data structure called the task context.
When a task is executing, it uses the processor and the registers available for all
sorts of processing. When a task leaves the processor for another task to execute
before it has finished its own, it should resume at a later time from where it stopped
and not from the first instruction. This requires the information about the task with
respect to the registers of the processor to be stored somewhere. This information
is recorded in the task context.
Task States
In an operation system there are always multiple tasks. At a time only one task can be executed.
This means that there are other tasks which are waiting their turn to be
executed.
Depending upon execution or not a task may be classified into the following three states:
Running state - Only one task can actually be using the processor at a given time that task
is said to be the “running” task and its state is “running state”. No other task can be in that
same state at the same time
Ready state - Tasks that are not currently using the processor but are ready to run are in
the “ready” state. There may be a queue of tasks in the ready state.
Waiting state - Tasks that are neither in running nor ready state but that are waiting for
some event external to themselves to occur before the can go for execution on are in the
“waiting” state.
Page 9
RTOS AND IDE FOR ESD MODULE-5
Process Concept:
Page 10
RTOS AND IDE FOR ESD MODULE-5
be running on any processor at any instant.
Process scheduling:
consists of all process in the system. The process that are residing in main memory and are
ready & waiting to execute or kept on a list called ready queue.
Process control block:
Each process is represented in the OS by a process control block. It is also by a process
control block. It is also known as task control block.
Page 11
RTOS AND IDE FOR ESD MODULE-5
A process control block contains many pieces of information associated with a specific
process. It includes the following informations.
Process state: The state may be new, ready, running, waiting or terminated state.
Program counter:it indicates the address of the next instruction to be executed
for this purpose.
CPU registers: The registers vary in number & type depending on the computer
architecture. It includes accumulators, index registers, stack pointer & general
purpose registers, plus any condition- code information must be saved when
an interrupt occurs to allow the process to be continued correctly after- ward.
CPU scheduling information:This information includes process priority pointers
to scheduling queues & any other scheduling parameters.
Memory management information: This information may include such
information as the value of the bar & limit registers, the page tables or the
segment tables, depending upon the memory system used by the operating
system.
Accounting information: This information includes the amount of CPU and real
time used, time limits, account number, job or process numbers and so on.
I/O Status Information: This information includes the list of I/O devices allocated to
this process, a list of open files and so on. The PCB simply serves as the repository for
any information that may vary from process to process
Page 12
RTOS AND IDE FOR ESD MODULE-5
Threads :
A process creates a thread through a system call. The thread does not have
resources of its own, so it does not have a context; it operates by using the
context of the process, and accesses the resources of the process through it.
We use the phrases ―thread(s) of a process‖ and ―parent process of a
thread‖ to describe the relationship between a thread and the process whose
context it uses.
Page 13
RTOS AND IDE FOR ESD MODULE-5
Page 14
RTOS AND IDE FOR ESD MODULE-5
POSIX Threads:
Page 15
RTOS AND IDE FOR ESD MODULE-5
Preemptive Scheduling:
It is the responsibility of CPU scheduler to allot a process to CPU whenever the CPU
is in the idle state. The CPU scheduler selects a process from ready queue and
allocates the process to CPU. The scheduling which takes place when a process
switches from running state to ready state or from waiting state to ready state is
called Preemptive Scheduling
Shortest Job First Scheduling (SJF) Algorithm: This algorithm associates with each
process if the CPU is available. This scheduling is also known as shortest next CPU
burst, because the scheduling is done by examining the length of the next CPU burst of
the process rather than its total length. Consider the following example:
Process CPU time
P1 3
P2 5
P3 2
P4 4
Solution:According to the SJF the Gantt chart will be
P3 P1 P2 P4
0 2 5 9 14
The waiting time for process P1 = 0, P2 = 2, P3 = 5, P4 = 9 then the turnaround time for
process P3 = 0 + 2 = 2, P1 = 2 + 3 = 5, P4 = 5 + 4 = 9, P2 = 9 + 5 =14.
Then average waiting time = (0 + 2 + 5 + 9)/4 = 16/4 = 4
Average turnaround time = (2 + 5 + 9 + 14)/4 = 30/4 =
7.5
The SJF algorithm may be either preemptive or non preemptive algorithm. The
preemptive SJF is also known as shortest remaining time first.
Consider the following example.
Process Arrival Time CPU time
P1 0 8
P2 1 4
P3 2 9
P4 3 5
Page 16
RTOS AND IDE FOR ESD MODULE-5
In this case the Gantt chart will be
P1 P2 P4 P1 P3
0 1 5 10 17 26
The waiting time for
process P1 = 10 - 1 =9
P2 = 1 – 1 = 0
P3 = 17 – 2 = 15
P4 = 5 – 3 = 2
The average waiting time = (9 + 0 + 15 + 2)/4 = 26/4 = 6.5
Round Robin Scheduling Algorithm: This type of algorithm is designed only for the time
sharing system. It is similar to FCFS scheduling with preemption condition to switch between
processes. A small unit of time called quantum time or time slice is used to switch between
the processes. The average waiting time under the round robin policy is quiet long. Consider
the following example:
Process CPU time
P1 3
P2 5
P3 2
P4 4
Page 17
RTOS AND IDE FOR ESD MODULE-5
Task Communication :
A shared memory is an extra piece of memory that is attached to some address spaces for
their owners to use. As a result, all of these processes share the same memory segment and
have access to it. Consequently, race conditions may occur if memory accesses are not
handled properly. The following figure shows two processes and their address spaces. The
yellow rectangle is a shared memory attached to both address spaces and both process 1
and process 2 can have access to this shared memory as if the shared memory is part of its
own address space. In some sense, the original address spaces is "extended" by attaching
this shared memory.
Page 18
RTOS AND IDE FOR ESD MODULE-5
A pipe is a method used to pass information from one program process to another. Unlike
other types of inter-process communication, a pipe only offers one-way communication by
passing a parameter or output from one process to another. The information that is passed
through the pipe is held by the system until it can be read by the receiving process. also
known as a FIFO for its behavior.
In computing, a named pipe (also known as a FIFO) is one of the methods for intern-
process communication.
It is an extension to the traditional pipe concept on Unix. A traditional pipe is
“unnamed” and lasts only as long as the process.
A named pipe, however, can last as long as the system is up, beyond the life of the
process. It can be deleted if no longer used.
Usually a named pipe appears as a file, and generally processes attach to it for inter-
process communication. A FIFO file is a special kind of file on the local storage which
allows two or more processes to communicate with each other by reading/writing
to/from this file.
A FIFO special file is entered into the filesystem by calling mkfifo() in C. Once we have
created a FIFO special file in this way, any process can open it for reading or writing,
in the same way as an ordinary file. However, it has to be open at both ends
simultaneously before you can proceed to do any input or output operations on it.
Message passing:
Page 19
RTOS AND IDE FOR ESD MODULE-5
Message queue:
Other implementations allow the passing of messages between different computer systems,
potentially connecting multiple applications and multiple operating systems. [4] These
message queueing systems typically provide enhanced resilience functionality to ensure
that messages do not get "lost" in the event of a system failure. Examples of commercial
implementations of this kind of message queueing software (also known as message-
oriented middleware) include IBM WebSphere MQ (formerly MQ Series) and Oracle
Page 20
RTOS AND IDE FOR ESD MODULE-5
Advanced Queuing (AQ). There is a Java standard called Java Message Service, which has
several proprietary and free software implementations.
Mail box:
Mailboxes provide a means of passing messages between tasks for data exchange or task
synchronization. For example, assume that a data gathering task that produces data needs
to convey the data to a calculation task that consumes the data. This data gathering task can
convey the data by placing it in a mailbox and using the SEND command; the calculation
task uses RECEIVE to retrieve the data. If the calculation task consumes data faster than the
gatherer produces it, the tasks need to be synchronized so that only new data is operated
on by the calculation task. Using mailboxes achieves synchronization by forcing the
calculation task to wait for new data before it operates. The data producer puts the data in
a mailbox and SENDs it. The data consumer task calls RECEIVE to check whether there is
new data in the mailbox; if not, RECEIVE calls Pause() to allow other tasks to execute while
the consuming task is waiting for the new data.
Page 21
RTOS AND IDE FOR ESD MODULE-5
Signaling :
signals are commonly used in POSIX systems. Signals are sent to the current process telling
it what it needs to do, such as, shutdown, or that it has committed an exception. A process
has several signal-handlers which execute code when a relevant signal is encountered. The
ANSI header for these tasks is <signal.h>, which includes routines to allow signals to be
raised and read.
Signals are essentially software interrupts. It is possible for a process to ignore most
signals, but some cannot be blocked. Some of the common signals are Segmentation
Violation (reading or writing memory that does not belong to this process), Illegal
Instruction (trying to execute something that is not a proper instruction to the CPU), Halt
(stop processing for the moment), Continue (used after a Halt), Terminate (clean up and
quit), and Kill (quit now without cleaning up).
RPC:
Page 22
RTOS AND IDE FOR ESD MODULE-5
Process Synchronization
Consider a system consisting of n processes (P0, P1, ………Pn -1) each process has
a segment of code which is known as critical section in which the process may be
changing common variable, updating a table, writing a file and so on. The
important feature of the system is that when the process is executing in its
critical section no other process is to be allowed to execute in its critical section.
Page 23
RTOS AND IDE FOR ESD MODULE-5
Page 24
RTOS AND IDE FOR ESD MODULE-5
Dining Philosopher Problem: Consider 5 philosophers to spend their lives in thinking &
eating. A philosopher shares common circular table surrounded by 5 chairs each occupies
by one philosopher. In the center of the table there is a bowl of rice and the table is laid
with 6 chopsticks as shown in below figure.
Page 25
RTOS AND IDE FOR ESD MODULE-5
When a philosopher thinks she does not interact with her colleagues. From time to time a
philosopher gets hungry and tries to pickup two chopsticks that are closest to her. A
philosopher may pickup one chopstick or two chopsticks at a time but she cannot pickup a
chopstick that is already in hand of the neighbor. When a hungry philosopher has both her
chopsticks at the same time, she eats without releasing her chopsticks. When she finished
eating, she puts down both of her chopsticks and starts thinking again. This problem is
considered as classic synchronization problem. According to this problem each chopstick is
represented by a semaphore. A philosopher grabs the chopsticks by executing the wait
operation on that semaphore. She releases the chopsticks by executing the signal operation on
the appropriate semaphore
Page 26
RTOS AND IDE FOR ESD MODULE-5
The Integrated Development Environment:
Integrated development environments are designed to maximize programmer productivity
by providing tight-knit components with similar user interfaces. IDEs present a single
program in which all development is done. This program typically provides many features
for authoring, modifying, compiling, deploying and debugging software. This contrasts with
software development using unrelated tools, such as vi, GCC or make.
One aim of the IDE is to reduce the configuration necessary to piece together multiple
development utilities, instead providing the same set of capabilities as a cohesive unit.
Reducing that setup time can increase developer productivity, in cases where learning to
use the IDE is faster than manually integrating all of the individual tools. Tighter
integration of all development tasks has the potential to improve overall productivity
beyond just helping with setup tasks. For example, code can be continuously parsed while
it is being edited, providing instant feedback when syntax errors are introduced. That can
speed learning a new programming language and its associated libraries.
Some IDEs are dedicated to a specific programming language, allowing a feature set that
most closely matches the programming paradigms of the language. However, there are
many multiple-language IDEs, such as Eclipse, ActiveState Komodo, IntelliJ IDEA, Oracle
JDeveloper, NetBeans, Codenvy and Microsoft Visual Studio. Xcode, Xojo and Delphi are
dedicated to a closed language or set of programming languages.
While most modern IDEs are graphical, text-based IDEs such as Turbo Pascal were in
popular use before the widespread availability of windowing systems like Microsoft
Windows and the X Window System (X11). They commonly use function keys or hotkeys to
execute frequently used commands or macros.
Page 27
RTOS AND IDE FOR ESD MODULE-5
A cross compiler is a compiler capable of creating executable code for a platform other
than the one on which the compiler is running. For example in order to compile for
Linux/ARM you first need to obtain its libraries to compile against.
A cross compiler is necessary to compile for multiple platforms from one machine. A
platform could be infeasible for a compiler to run on, such as for the microcontroller of an
embedded system because those systems contain no operating system. In
paravirtualization one machine runs many operating systems, and a cross compiler could
generate an executable for each of them from one main source.
Cross compilers are not to be confused with a source-to-source compilers. A cross
compiler is for cross-platform software development of binary code, while a source-to-
source "compiler" just translates from one programming language to another in text code.
Both are programming tools.
The fundamental use of a cross compiler is to separate thebuild environment from target
environment. This is useful in a number of situations:
Embedded computers where a device has extremely limited resources. For example, a
microwave oven will have an extremely small computer to read its touchpad and door
sensor, provide output to a digital display and speaker, and to control the machinery for
cooking food. This computer will not be powerful enough to run a compiler, a file system,
or a development environment. Since debugging and testing may also require more
resources than are available on an embedded system, cross- compilation can be less
involved and less prone to errors than native compilation.
Compiling for multiple machines. For example, a company may wish to support several
different versions of an operating system or to support several different operating
systems. By using a cross compiler, a single build environment can be set up to compile for
each of these targets.
Compiling on a server farm. Similar to compiling for multiple machines, a complicated
build that involves many compile operations can be executed across any machine that is
free, regardless of its underlying hardware or the operating system version that it is
running.
Page 28
RTOS AND IDE FOR ESD MODULE-5
Bootstrapping to a new platform. When developing software for a new platform, or the
emulator of a future platform, one uses a cross compiler to compile necessary tools such
as the operating system and a native compiler.
What is a Disassembler?
Decompilers
Decompilers take the process a step further and actually try to reproduce the code in a
high level language. Frequently, this high level language is C, because C is simple and
primitive enough to facilitate the decompilation process. Decompilation does have its
drawbacks, because lots of data and readability constructs are lost during the original
compilation process, and they cannot be reproduced. Since the science of decompilation is
still young, and results are "good" but not "great", this page will limit itself to a listing of
decompilers, and a general (but brief) discussion of the possibilities of decompilation.
Page 29
RTOS AND IDE FOR ESD MODULE-5
Tools
As with other software, embedded system designers use compilers, assemblers, and
debuggers to develop embedded system software. However, they may also use some more
specific tools:
For systems using digital signal processing, developers may use a math workbench such
as Scilab / Scicos, MATLAB / Simulink, EICASLAB, MathCad, Mathematica,or FlowStone
DSP to simulate the mathematics. They might also use libraries for both the host and
target which eliminates developing DSP routines as done in DSPnano RTOS.
model based development tool like VisSim lets you create and simulate graphical data
flow and UML State chart diagrams of components like digital filters, motor controllers,
communication protocol decoding and multi-rate tasks. Interrupt handlers can also be
created graphically. After simulation, you can automatically generate C-code to the VisSim
RTOS which handles the main control task and preemption of background tasks, as well as
automatic setup and programming of on-chip peripherals.
Debugging
An in-circuit debugger (ICD), a hardware device that connects to the microprocessor via a
JTAG or Nexus interface. This allows the operation
Page 30
RTOS AND IDE FOR ESD MODULE-5
Simulation is the imitation of the operation of a real-world process or system over time.[1]
The act of simulating something first requires that a model be developed; this model
represents the key characteristics or behaviors/functions of the selected physical or
abstract system or process. The model represents the system itself, whereas the simulation
represents the operation of the system over time.
Key issues in simulation include acquisition of valid source information about the relevant
selection of key characteristics and behaviours, the use of simplifying approximations and
assumptions within the simulation, and fidelity and validity of the simulation outcomes.
Page 31
RTOS AND IDE FOR ESD MODULE-5
Emulator
This article is about emulators in computing. For a line of digital musical instruments, see
E-mu Emulator. For the Transformers character, see Circuit Breaker
(Transformers).#Shattered Glass. For other uses, see Emulation (disambiguation).
The above described focus on exact reproduction of behavior is in contrast to some other
forms of computer simulation, in which an abstract model of a system is being simulated.
For example, a computer simulation of a hurricane or a chemical reaction is not emulation.
OUT-OF-CIRCUIT :The code to be run on the target embedded system is always developed
on the host computer. This code is called the binary executable image or simply hex code.
The process of putting this code in the memory chip of the target embedded system is
called Downloading.
Page 32
RTOS AND IDE FOR ESD MODULE-5
There are two ways of downloading the binary image on the embedded system:
1. Using a Device Programmer
A device programmer is a piece of hardware that works in two steps.
Step 1 Once the binary image is ready on the computer, the device programmer is
connected to the computer and the binary image is transferred to the device programmer.
Step 2 The microcontroller/microprocessor or memory chip, usually the ROM which is
supposed to contain the binary image is placed on the proper socket on the device
programmer. The device programmer contains a software interface through which the user
selects the target microprocessor for which the binary image has to be downloaded. The
Device programmer then transfers the binary image bit by bit to the chip.
2. Using In System Programmer(ISP)
Certain Target embedded platforms contain a piece of hardware called ISP that have a
hardware interface to both the computer as well the chip where the code is to be
downloaded.
The user through the ISP’s software interface sends the binary image to the target board.
This avoids the requirement of frequently removing the microprocessor / microcontroller
or ROM for downloading the code if a device programmer had to be used.
DEBUGGING THE EMBEDDED SOFTWARE
Debugging is the process of eliminating the bugs/errors in software.
The software written to run on embedded systems may contain errors and hence
needs debugging.
However, the difficulty in case of embedded systems is to find out the bug/ error
itself. This is because the binary image you downloaded on the target board was free
of syntax errors but
Page 33
RTOS AND IDE FOR ESD MODULE-5
still if the embedded system does not function the way it was supposed to be then it can be
either because of a hardware problem or a software problem. Assuming that the hardware
is perfect all that remains to check is the software.
The difficult part here is that once the embedded system starts functioning there is
no way for the user or programmer to know the internal state of the components on
the target board.
The most primitive method of debugging is using LEDs. This is similar to using a
printf or a cout statement in c/c++ programs to test if the control enters the loop or
not. Similarly an LED blind or a pattern of LED blinks can be used to check if the
control enters a particular piece of code.
Remote Debuggers
Remote Debugger is a tool that can be commonly used for:
Downloading
Executing and
Debugging embedded software
A Remote Debugger contains a hardware interface between the host computer and
the target embedded system.
Page 34
RTOS AND IDE FOR ESD MODULE-5
Page 35