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

OS Module 1

Uploaded by

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

OS Module 1

Uploaded by

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

Introduction on

Operating System
INTRODUCTION

• Modern computer consists of one or more processors, some main


memory, disks, printers, a keyboard, a mouse, a display, network
interfaces, and various other input/output devices. All in all, a complex
system.
• If every application programmer had to understand how all these
things work in detail, no code would ever get written. Furthermore,
managing all these components and using them optimally is an
exceedingly challenging job. For this reason, computers are equipped
with alayer of software called the operating system,
• 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).
• Kernel complete access to all the hardware and can execute any instruction the machine is capable
of executing.
• The rest of the software runs in user mode, in which only a subset of the machine instructions is
available.
• In particular, those instructions that affect control of the machine or do I/O )Input/Output" are
forbidden to user-mode programs.
What is an Operating System
• An operating system (OS) is the program that, after being initially loaded into the
computer by a boot program, manages all of the other application programs in a
computer. The application programs make use of the operating system by making
requests for services through a defined application program interface (API).
• An operating system is a program that acts as an interface between the computer user
and computer hardware, and controls the execution of programs.
• operating systems perform two essentially unrelated functions:
1. providing application programmers (and application programs, naturally) a clean abstract set of
resources instead of the messy hardware ones and
2. managing these hardware resources.
• Some examples of operating systems include Apple macOS, Microsoft Windows,
Google's Android OS, Linux Operating System, and Apple iOS.
The Operating System as an Extended Machine

• The architecture (instruction set, memory organization, I/O, and bus structure) of most computers at the
machine-language level is primitive and awkward to program, especially for input/output.
• software, called a disk driver, deals with the hardware and provides an interface to read and write disk
blocks, without getting into the details. Operating systems contain many drivers for controlling I/O devices.
The Operating System as a Resource Manager

• The concept of an operating system as primarily providing abstractions to


application programs is a top-down view. An alternative, bottom-up, view holds
that the operating system is there to manage all the pieces of a complex system.
• Modern computers consist of processors, memories, timers, disks, mice, network
interfaces, printers, and a wide variety of other devices. In the bottom-up view, the
job of the operating system is to provide for an orderly and controlled allocation
of the processors, memories, and I/O devices among the various programs
wanting them.
• Resource management includes multiplexing (sharing) resources in two different
ways: in time and in space.
PROCESSES
process: an abstraction of a running program.

A program in this state of execution is what we call a


process.
A program exists on a hard drive; a process exists in RAM.
They support the ability to have (pseudo) concurrent operation even
when there is only one CPU available. They turn a single CPU into
multiple virtual CPUs. Without the process abstraction, modern
computing could not exist.
PROCESSES
All modern computers often do several things at the same time.
Now consider a user PC. When the system is booted, many processes are secretly
started, often unknown to the user.
For example, a process may be started upto wait for incoming email. Another
process may run on behalf of the antivirus program to check periodically if any
new virus definitions are available.
In addition,explicit user processes may be running, printing files and backing up
the
user’s photos on a USB stick, all while the user is surfing the Web.
All this activity has to be managed, and a multiprogramming system supporting
multiple processes comes in very handy here.
In any multiprogramming system, the CPU switches from process to
process quickly, running each for tens or hundreds of milliseconds. While,
strictly speaking, at any one instant the CPU is running only one process,
in the course of 1 second it may work on several of them, giving the
illusion of parallelism.
multiprocessor systems -which have two or more CPUs sharing the same
physical memory.
Keeping track of multiple, parallel activities is hard for people to do.
Therefore, operating system designers over the years have evolved a
conceptual model (sequential processes) that makes parallelism easier to
deal with.
The Process Model
A process is just an instance of an executing program, including the current values of
the program counter, registers, and variables. Conceptually, each process has its own
virtual CPU.
In Fig. 2-1(a) we see a computer multiprogramming four programs in memory.
In Fig. 2-1(b) we see four processes, each with its own flow of control (i.e., its own
logical program counter), and each one running independently of the other ones.
Of course, there is only one physical program counter, so when each process runs,its
logical program counter is loaded into the real program counter. When it is finished
(for the time being), the physical program counter is saved in the process’
stored logical program counter in memory. In Fig. 2-1(c) we see that, viewed overa
long enough time interval, all the processes have made progress, but at any giv en
instant only one process is actually running.
Explanation of Process

1. Text Section: A Process, sometimes known as the Text Section, also includes the
current activity represented by the value of the Program Counter.
2. Stack: The stack contains temporary data, such as function parameters, returns
addresses, and local variables.
3. Data Section: Contains the global variable.
4. Heap Section: Dynamically allocated memory to process during its run time.
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
void forkexample()
{
pid_t p;
p = fork();
if(p<0)
{
perror("fork fail");
exit(1);
}
// child process because return value zero
else if ( p == 0)
printf("Hello from Child!=%d",getpid());

// parent process because return value non-zero.


else
printf("Hello from Parent!=%d\n",getppid());
}
i
int main()
{
forkexample();
return 0;
}
Process Termination
After a process has been created, it starts running and does whatever
its job is.However, nothing lasts forever, not even processes. Sooner or
later the new process will terminate, usually due to one of the
following conditions:
1. Normal exit .
2. Error exit .
3. Fatal error .
4. Killed by another process .
Most processes terminate because they have done their work.
When a compiler has compiled the program given to it, the
compiler executes a system call to tell the operating system that
it is finished. This call is exit in UNIX and ExitProcess in
Windows.
Screen-oriented programs also support voluntary termination.
Word processors, Internet browsers, and similar programs
always have an icon or menu item that the user can click to tell
the process to remove any temporary files it has open and then
terminate.
2.The second reason for termination is that the process discovers a fatal
error.For example, if a user types the command
cc foo.c
to compile the program foo.c and no such file exists, the compiler simply
announces this fact and exits.

3.The third reason for termination is an error caused by the process, often
due to
a program bug. Examples include executing an illegal instruction, referencing
nonexistent memory, or dividing by zero.
4.The fourth reason a process might terminate is that the process
executes a system call telling the operating system to kill some other
process.
nt child,parent;
pid_t p;
p = fork();
f(p<0)

perror("fork fail");
exit(1);

/ child process because return value zero


else if ( p == 0)

child=getpid();
// parent process because return value non-zero.
else
{ parent=getppid();
printf("Hello from Parent!=%d\n",getppid()); }
kill(p, SIGKILL);}

int main()
{
forkexample();
return 0;}

You might also like