OS - Scheme-1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 19

SJCIT

DEPARTMENT: ARTIFICIAL INTELLIGENCE AND DATA SCIENCE

Scheme & Solutions- TEST-I


Date: 22/10/2024
Semester: 3 Subject Title: OPERATING SYSTEMS Subject Code: BCS303

Marks
Q.No Solution
Allocated
5M

Distinguish between the following terms.


(i) Multiprogramming and Multitasking
(ii) Multiprocessor System and Clustered System.

Multitasking System and Multiprogramming: Time sharing (or multitasking) is a


logical extension of multiprogramming. In time-sharing systems, the CPU executes
multiple jobs by switching among them, but the switches occur so frequently that the users
can interact with each program while it is running. A time-shared operating system uses
CPU scheduling and multiprogramming to provide each user with a small portion of a
time-shared computer. Each user has at least one separate program in memory. A program
loaded into memory and executing is called a process.
Time-sharing and multiprogramming require several jobs to be kept simultaneously in
memory. Since in general main memory is too small to accommodate all jobs, the jobs are
kept initially on the disk in the job pool.

Q1. Multiprocessor systems and clustered systems: Multiprocessor systems (also known as
parallel systems or tightly coupled systems) are growing in importance. Such systems have 5M
two or more processors in close communication, sharing the computer bus and sometimes
the clock, memory, and peripheral devices.
Clustered systems differ from multiprocessor systems, however, in that they are composed
of two or more individual systems coupled together. Clustering is usually used to provide
high-availability service; that is, service will continue even if one or more systems in the
cluster fail. High availability is generally obtained by adding a level of redundancy in the
system.

To completely understand the role of operating system, two views are considered:

1. User View: The user view of the computer depends on the interface used. Some users may
use PC’s. Such system is designed for one user. Here the OS is designed for ease of use where
some attention is mainly on performances and not on the resource utilization.
may access the same computer through other terminals. These users may share resources and
exchange information. In this case the OS is designed to maximize resource utilization – so
that all available CPU time, memory & I/O are used efficiently.

servers, then the user have a system unit of their own and shares resources and files with other
systems. In this case OS is designed to compromise between individual usability & resource
utilization.
SJCIT

per amount of battery life.

dded systems used in home devices (like washing m/c) &


automobiles do not have any user interaction. There are some LEDs to show the status of its
work. 7M

2. System View: An operating system can be viewed as resource allocator and


control program.

A computer system has many resources such as CPU Time, memory space, file storage space,
I/O devices and so on that may be used to solve a problem.

programs and the users so that it can operate the computer system efficiently and fairly.

is a control program which manages the execution of user programs to prevent errors and
improper use of the computer.

2. Define a virtual machine (VM) .With a neat diagram, explain the working of a virtual
machine and give its benefits.

The fundamental idea behind a virtual machine is to abstract the hardware of a single
computer (the CPU, memory, disk drives, network interface cards, and so on) into several
different execution environments, thereby creating the illusion that each separate execution
environment is running its own private computer. By using CPU scheduling and virtual-
memory techniques, an operating system can create the illusion that a process has its own
processor with its own (virtual) memory. Each process is provided with a (virtual) copy of the
underlying computer as shown in the below figure.

A major difficulty with the virtual machine approach involves disk systems. Suppose that the 10M
physical machine had three disk drives but wanted to support seven virtual machines. Clearly,
it could not allocate a disk drive to each virtual machine, because the virtual machine software
SJCIT

itself will need substantial disk space to provide virtual memory and spooling. The solution is
to provide virtual disks-termed mini disks in IBM's VM operating system which are identical
in all respects except size.

It is difficult to implement VM concept. Much work is required to provide an exact duplicate


of the underlying machine. The machine typically has two modes: user mode and kernel
mode. The virtual-machine software can run in kernel mode, since it is the operating system.
The virtual machine itself can execute in only user mode. The major difference between
Q2. virtual and non- virtual m/c is time. The real I/O might have taken 100 milliseconds, the
virtual I/O might take less time (because it is spooled) or more time (because it is interpreted).
In addition, the CPU is being multi programmed among many virtual machines, further
slowing down the virtual machines in unpredictable ways.

 Benefits

• The virtual-machine concept provides complete protection of system resources since


each virtual machine is isolated from all other virtual machines. This isolation permits
no direct sharing of resources.
• A virtual-machine system is a perfect vehicle for operating-systems research and
development. System programmers are given their own VM, and system development
is done on the virtual machine instead on a physical machine. Thus changing OS will
not cause any problem.

Distinguish between the following:


a) Batch and distributed operating system
b) Real time and clustering systems
c) Symmetric and asymmetric multiprocessing
Batch Operating System Distributed Operating System

Processes jobs in groups or Manages a collection of


Definition
batches. independent computers.

Non-interactive; executes jobs Processes can execute


Process Execution
sequentially. concurrently on different nodes.

Resource Limited to job scheduling and Requires network management 3M


Management resource allocation. and resource sharing.

IBM’s OS/360, Unix batch


Examples Google Cloud, Amazon EC2.
processing.

Limited; may lose jobs if a failure Can be designed for high


Fault Tolerance
occurs. availability and redundancy.
Q3.
Limited; scaling requires Highly scalable by adding more
Scalability
significant overhead. nodes.

Real time and clustering systems


SJCIT

Criteria Real-Time Systems Clustering Systems

Definition Responds to inputs within Combines multiple


strict time constraints. computers to work as a
single system.

Process Execution Must guarantee timely task Nodes work together for load
completion. balancing.
3M
Resource Management Prioritizes tasks based on Manages resources across
timing requirements. multiple machines.

Examples Flight control systems, Beowulf clusters, Oracle


medical monitoring. RAC.

Fault Tolerance Critical; failure could result High availability with


in severe consequences. failover capabilities.

Scalability Generally fixed; must meet Can scale by adding more


real-time requirements. nodes.

Symmetric and asymmetric multiprocessing


Symmetric Multiprocessing Asymmetric Multiprocessing
Criteria (SMP) (AMP)

Multiple processors share the Processors have dedicated


Definition same memory and I/O. tasks and resources.

Only one processor controls


Process Execution All processors are equal and the system while others are
can execute any task. 4M
slaves.
Each processor manages its
Resource Management Global resource management own resources
among processors.
independently.

Intel’s multi-core processors, Embedded systems, some


Examples modern servers. real-time applications.

Can provide redundancy, but Limited; failure of the master


Fault Tolerance not always guaranteed. can halt the system.

Can scale by adding more Limited by the master


Scalability node’s processors. capacity.

What is IPC? Illustrate the 2 fundamental models of IPC with block


diagram?
SJCIT

Inter-process communication (IPC) is a set of techniques used in operating systems to allow


processes to communicate with each other. IPC is essential for coordinating activities, sharing
data, and managing resources among multiple processes.
Q4. 1M
Or

Cooperating processes require an Inter-process Communication (IPC) mechanism that will


allow them to exchange data and information. There are two fundamental models of IPC
as shown in figure.

1. Shared memory: A region of memory that is shared by cooperating


processes is established. Processes then exchange information by reading
and writing data to the shared region.
2. Message passing: Communication takes place by means of message
exchange between the cooperating processes.

4M

Communication models (a) Message passing. (b) Shared memory.

The differences between these two models are,

Message passing Shared memory


a. Useful for exchanging
a. large data
small amount of data.
b. easy to implement b. complex
c. slower c. faster
d. system calls are required only to
d. implemented using system calls
establish Shared memory region
Shared Memory System: A region of memory that is shared by cooperating processes is
established. Processes then exchange information by reading and writing data to the shared
region.

• To illustrate cooperating processes, consider producer-consumer problem. 5M


• Producer process produces information that is consumed by a consumer process.
• One solution to producer-consumer problem uses shared memory. To allow producer
and consumer processes to run concurrently, there must be a buffer of items that can
be filled by a producer and emptied by consumer. The buffer will reside in a shared
memory region.
SJCIT

•The producer can produce one item while the consumer is consuming another item.
The producer and consumer must be synchronized, so that the consumer does not try
to consume an item that has not yet been produced by the producer.
Two types of buffers can be used.

Unbounded-buffer: places no practical limit on the size of the buffer. The consumer may
have to wait for new items, but the producer can always produce new items.

Bounded-buffer: assumes that there is a fixed buffer size, so the consumer must wait if the
buffer is empty, and the producer must wait if the buffer is full.

Message Passing System

Communication takes place by means of message exchange between the cooperating


processes.

Message passing facility provides two operations.

o Send (message)

o Receive (message)

Message size can be fixed or variable.

If P and Q wish to communicate, they need to establish a communication link

between them and communication link can be,

o physical (eg: shared memory, hardware bus)

o logical (eg: logical properties)

Several methods for logically implementing a link are,

o Direct or Indirect communication

o Synchronous or asynchronous communication

o Automatic or explicit buffering

Processes that want to communicate must have a way to refer to each other. They can
use either direct or indirect communication.

Under Direct Communication processes must name each other explicitly


10M
The send() and receive() primitives are defined as,

o Send (P, message) – send a message to process P.

o Receive (Q, message) – receive a message from process

Q. Properties of communication link in this scheme are,


SJCIT

o Links are established automatically between every pair of processes that want to
communicate.

o A link is associated with exactly two communicating processes.

o Between each pair there exists exactly one

link. This scheme exhibits two types of

addressing,

o Symmetry: Both sender and receiver must name the other to communicate.

o Asymmetry: Only the sender names the recipient, the recipient is not required to
name the sender. The send() and receive() primitives are defined as,

Send (P, message) – send a message to process P

Receive (id, message) – receive a message from any process; the variable id is set to the
name of the process with which communication has taken place.

In Indirect Communication messages are sent and received from mailboxes

(also referred to as ports)

A mailbox can be viewed abstractly as an object into which messages can be placed by
processes and from which messages can be removed.

Each mailbox has a unique id and processes can communicate only if they share a mailbox.

The send() and receive() primitives are defined as,

o Send (A, message) – send a message to mailbox A

o Receive (A, message) – receive a message from mailbox A

Properties of communication link are,

o Links are established only if processes share a common mailbox.

o A link may be associated with many processes.

o Each pair of processes may share several communication links.

OS allows the process to do the following operations

o create a new mailbox

o send and receive messages through mailbox

o destroy a mailbox

Synchronization

Message passing may be either blocking or non-blocking. Blocking is considered


SJCIT

synchronous. Non-blocking is considered asynchronous.


SJCIT

o Blocking send: The sending process is blocked until the message is received by the
receiving process or by the mailbox.

o Non-blocking send: The sending process sends the message and resumes operation.

o Blocking receive: The receiver blocks until a message is available.

o Non-blocking receive: The receiver retrieves either a valid message or a null.

Buffering: Messages exchanged by communicating processes reside in a temporary queue,


and such queues can be implemented in one of three ways,

1. Zero capacity – Maximum length is zero and sender must wait for the receiver.

2. Bounded capacity – finite length ofn messages, sender must wait if link is full.

3. Unbounded capacity – infinite length and sender never waits.

What are system calls? With examples mention different types of system
calls and also demonstrate system calls for copying contents from one file to
another file.

System calls are the fundamental interface between an application and the operating system.
They allow user-space applications to request services from the operating system kernel,
such as file operations, process control, and network communication. System calls provide a
controlled way for programs to interact with the hardware and the OS without compromising
system stability and security. An interface provided by the system to the services made
available by an OS is called “System Call”.

There are 5 types of system calls. They are,

Q5. i) Process control: Manage process execution and control.


10M

Ex: end, abort, load, execute, create process, terminate process, wait for time, get process
attributes, set process attributes, wait event, signal event, allocate and free memory.

ii) File management: These programs create, delete, copy, rename, print, dump, list,
and generally manipulate files and directories.

Ex: create file, delete file, open, close, read, write, reposition, get file attributes, set file
attributes.

iii) Device management: Interact with hardware devices.


SJCIT

Ex: request device, release device, read, write, reposition, get device attributes, set device
attributes, logically attach or detach devices.
v) Information management: Get or set system information.

Ex: get time or date, set time or date, get system data, set system data, get process, file or
device attributes, set process, file or device attributes

v) Communications: These programs provide the mechanism for creating virtual connections
among processes, users, and computer systems. They allow users to send messages to one
another's screen, to browse web pages, to send electronic- mail messages, to log in remotely,
or to transfer files from one machine to another.

Ex: create, delete communication connection, send, receive messages, transfer status
information, attach or detach remote devices.

System call sequence to read the contents of one file and copy to another file is illustrated in
below figure shown below:

many ways. This sequence requires many I/O system calls.


2M

file fails, it should display error message on console (another system call) and should terminate
abnormally (another system call).

e program must create the output file (another system call), If fails, it should
display error message on console (another system call) and should also abort (another system
call).

to the output file


(system call).Write/read operation may fail, which needs another system call to continue.

message to console (system call)), and terminate normally (system call).


SJCIT

Illustrate dual mode operation of operating system with neat block diagram

To ensure proper execution of the OS, we must be able to distinguish between OS code and
user defined code. Most computer systems provide hardware support to differentiate among
various modes of execution.

Two modes of operations:

1. User mode
2. Kernel mode (also called supervisor, system or privileged mode)
 Mode bit is added to the hardware to indicate current mode: User mode (1) and
Kernel mode (0).
 When system is executing on behalf of user application, it is in user mode.
Q6.  When an user application requests a service from OS, it must transit from
user to kernel mode to fulfill the request as shown in figure.
Transition from user to kernel mode: At system boot time, the hardware starts in
kernel mode. The OS is then loaded and starts user applications in user mode. Whenever
a trap or interrupt occurs, the hardware switches from user mode to kernel mode.
Thus whenever the OS gains control of the computer, it is in kernel mode. The system
always switches to user mode before passing control to user program.
2M
8M

The hardware allows privileged instructions to be executed only in kernel mode. If an


attempt is made to execute privileged instructions in user mode, the hardware does not
execute it but rather treats it as an illegal and traps it to the OS. Examples: Instruction to
switch to user mode, I/O control instructions, timer management instructions and interrupt
management instructions.

Explain process operations with example program


The processes in most systems can execute concurrently, and they may be created and deleted
dynamically. Thus, these systems must provide a mechanism for process creation and
Q7 termination.

 Process Creation

 A process may create several new processes by some create-process system call, during
the course of execution.

 The creating process is called parent process and the created one is called the child
SJCIT

process. Each of the new process may in turn create other processes, forming a tree of
SJCIT

processes. Processes are identified by unique process identifier ( or pid).

 Below Figure. shows the process tree for the solaris OS. The process at the top of the
tree is sched process, with pid of 0,and this creates several children processes. The sched
process creates several children processes including pageout and fsflush. These
processes are responsible for managing memory and file systems. The sched process also
creates the init process, which serves as the root parent process for all user processes.
These processes are responsible for managing memory and file systems.

 inetd and dtlogin are two children of init where inetd is responsible for networking
services such as telnet and ftp; dtlogin is the process representing a user login screen.

 When a user logs in, dtlogin creates an X-windows session (Xsession), which in turns 10M
creates the sdt_shel process. Below sdt_shel, a user's command-line shell, the C-shell or
csh is created. In this command line interface, the user can then invoke various child
processes, such as the ls and cat commands.

 There is also csh process with pid of 7778 representing a user who has logged onto the
system using telnet. This user has started the Netscape browser (pid of 7785) and the
emacs editor (pid of 8105).

 A process needs certain resources to accomplish its task. Along with the various logical
and physical resources that a process obtains when it is created, initialization data may
be passed along by the parent process to the child process.

 When a process creates a new process, two possibilities exist in terms of execution.

1. The parent continues to execute concurrently with its children.

2. The parent waits until some or all of the children have terminated.

 There are also two possibilities in terms of the address space of the new process.

1. The child process is a duplicate of the parent process.

2. The child process has a new program loaded into it.

 In UNIX OS, fork () system call creates new process. In windows Create Process() does
the job.

 Exec () system call is called after a fork () to replace the process memory space with a
new program.

3M
SJCIT

 If there are two different processes running a copy of the same program, the pid for
child is zero and for the parent it is greater than zero. The parent process waits for the
child process to complete with the wait () system call.

 When the child process completes, the parent process resumes from the call to wait(),
where it completes using exit() system call. This is shown in below figure.

Process Termination

 A process terminates when it finishes executing its last statement and asks the operating
system to delete it by using exit() system call.

 Process resources are deallocated by the operating system. A process can terminate
another process via Terminate Process() system call. A Parent may terminate
execution of children processes (abort) for the following reasons.

o Child has exceeded usage of allocated resources.

o Task assigned to child is no longer required.

o If parent is exiting some operating system do not allow child to continue if its parent
terminates.

 Some systems does not allow child to exist if its parent has terminated. If process
terminates then all its children must also be terminated, this phenomenon is referred as
cascading termination.

Generalize the concept process state diagram and PCB with a neat block
diagram.

A process in an operating system is represented by a data structure known as a Process


Control Block (PCB) and it is also called as task control block. The following figure
shows the process control block.

5M
Q8.
SJCIT

The PCB contains important information about the specific process including,

o Process state: The current state of the process i.e., whether it is ready, running, waiting,
halted and so on.

o Program counter: Indicates the address of the next instruction to be executed for a process.

o CPU registers: The registers vary in number and type. Along with program counter this
state information should be saved to allow process to be continued correctly after an interrupt
occurs as shown in below figure.

o CPU scheduling information: This information includes a process priority, pointers to


scheduling queues, and any other scheduling parameters.

o Memory-management information: This information may include the value of base and
limit registers, the page tables, or the segment tables, depending on the memory system used
by the OS.

o Accounting information: This information includes the amount of CPU and real time used,
time limits, account numbers, job or process numbers, and so on.

o I/O status information: This information includes the list of I/O devices allocated to the
process, a list of open files, and so on.

5M

CPU switch from process to process


With neat Diagram describe the different types of multithreaded models
and Mention its advantages and disadvantages.
Support for threads may be provided either at user level for user threads or by the kernel for
kernel threads. There must be a relationship between user threads and kernel threads. Three
common ways of establishing this relationship are,
 Many-to-One
• Many user-level threads are mapped to single kernel thread as shown in below figure.
SJCIT

• This model is efficient as the thread management is done by the thread library in user
space, but the entire process will block if a thread makes a blocking system call.
Q9
• As only one thread can access the kernel thread at a time, multiple threads are unable
to run in parallel on multiprocessors.
• Examples: Solaris Green Threads, GNU Portable Threads.

One-to-One: Each user-level thread maps to kernel thread as shown in figure.

• It provides more concurrency than Many-to-One model by allowing thread to run


when a thread makes a blocking system call.
• It allows multiple threads to run in parallel on multiprocessors.
• The only drawback is, creating a user thread requires creating the corresponding
kernel thread and it burdens performance of an application.
• Examples: Windows NT/XP/2000, Linux

10M

Many-to-Many Model: One-to-One model restricts creating more user threads and Many-to-
One model allows creating more user threads but kernel can schedule only one thread at a
time.

• These drawbacks can be overcome by Many-to-Many model as shown in below


figure. (Left side)
• Many-to-Many model allows many user level threads to be mapped to many kernel
threads.
• It allows the operating system to create a sufficient number of kernel threads.
• When thread performs a blocking system call, the kernel can schedule another thread
for execution.
• It allows user-level thread to be bound to a kernel thread and this is referred as two-
level model as shown in below figure. (Right side)
SJCIT

• Examples: IRIX, HP-UX, Solaris OS.

Discuss the operating system services and also summarize the various categories
of system programs.

An OS provides an environment for the execution of the programs. The common services
provided by the OS are

1. User interface: Almost all operating systems have a user interface (UI).This interface can
take several forms.

a. Command-Line interface (CLI): uses text commands and a specific method for entering
them.

Q10. b. Batch Interface: commands and directives to control are entered into files and those files are
executed.
10M

c. Graphical User Interface (GUI): most common. Interface is a window system with a
pointing device directing the I/O, choose from menus, make selections along with keyboard to
enter text.

2. Program Execution: The OS must able to load the program into memory & run that
program. The program must be able to end its execution either normally or abnormally.
SJCIT

3. I/O Operation: A running program may require I/O( file or an I/O device). Users cannot
control the I/O devices directly. So the OS must provide a means for controlling I/O devices.

4. File System manipulation: Program needs to read and write files and directories. They also
need to create and delete files, search for a given file and list file information. Some programs
include permission management to deny access to files or directories based on file ownership.

5. Communication: In certain situation one process may need to exchange information with
another process. This communication may takes place in two ways.

i. Between the processes executing on the same computer.

ii.Between the processes executing on different computer that are connected by a network.

Communications can be implemented via shared memory or by message passing, in which


packets of information are moved between processes by the OS.

6. Error Detection: Errors may occur in CPU, I/O devices or in Memory Hardware. The OS
constantly needs to be aware of possible errors. For each type of errors the OS should take
appropriate actions to ensure correct & consistent computing.

7. Resource Allocation: When multiple users logs onto the system or when multiple jobs are
running, resources must be allocated to each of them. The OS manages different types of OS
resources. Some resources may need some special allocation codes & others may have some
general request & release code.

8. Accounting: We need to keep track of which users use how many & what kind of resources.
This record keeping may be used for accounting. This accounting data may be used for
statistics or billing. It can also be used to improve system efficiency.

9. Protection and security: Protection ensures that all the access to the system are controlled.
Security starts with each user having authenticated to the system, usually by means of a
password. External I/O devices must also be protected from invalid access. In multi process
environment it is possible that one process may interface with the other or with the OS, so
protection is required.

Signature of Faculty Signature of HOD

You might also like