Model Ans
Model Ans
Model Ans
MODEL ANSWER
Class: S.Y.B.Sc. I.T. Semester : III
Sub: Programming Principles with C
Q1. Attempt any three of the following: 15 Marks
a) Define Operating System. Explain its function.
Ans. The Operating System is a program with the following features −
An operating system is a program that acts as an interface between the software and the computer hardware.
It is an integrated set of specialized programs used to manage overall resources and operations of the
computer.
Functions of Operating System
Here is a list of some of the most prominent functions of Operating Systems –
1. Process management:- Process management helps OS to create and delete processes. It also provides
mechanisms for synchronization and communication among processes.
2. Memory management:- Memory management module performs the task of allocation and de-allocation of
memory space to programs in need of this resources.
3. File management:- It manages all the file-related activities such as organization storage, retrieval, naming,
sharing, and protection of files.
4. Device Management: Device management keeps tracks of all devices. This module also responsible for this
task is known as the I/O controller. It also performs the task of allocation and de-allocation of the devices.
5. I/O System Management: One of the main objects of any OS is to hide the peculiarities of that hardware
devices from the user.
6. Secondary-Storage Management: Systems have several levels of storage which includes primary storage,
secondary storage, and cache storage. Instructions and data must be stored in primary storage or cache so that a
running program can reference it.
7. Security:- Security module protects the data and information of a computer system against malware threat and
authorized access.
8. Command interpretation: This module is interpreting commands given by the and acting system resources to
process that commands.
9. Networking: A distributed system is a group of processors which do not share memory, hardware devices, or
a clock. The processors communicate with one another through the network.
10. Job accounting: Keeping track of time & resource used by various job and users.
11. Communication management: Coordination and assignment of compilers, interpreters, and another software
resource of the various users of the computer systems.
1|Page
The Heap is used for the dynamic memory allocation, and is managed via calls to new, delete, malloc, free,
etc.
The Stack is used for local variables. Space on the stack is reserved for local variables when they are declared.
Different Process States
Processes in the operating system can be in any of the following states:
NEW- The process is being created.
READY- The process is waiting to be assigned to a processor.
RUNNING- Instructions are being executed.
WAITING- The process is waiting for some event to occur(such as an I/O completion or reception of a signal).
TERMINATED- The process has finished execution.
e) Explain the First Come First Serve (FCFS) scheduling algorithm with example.
Ans . In the "First come first serve" scheduling algorithm, as the name suggests, the process which arrives first, gets
executed first, or we can say that the process which requests the CPU first, gets the CPU allocated first.
First Come First Serve, is just like FIFO(First in First out) Queue data structure, where the data element which
is added to the queue first, is the one who leaves the queue first.
This is used in Batch Systems.
It's easy to understand and implement programmatically, using a Queue data structure, where a new process
enters through the tail of the queue, and the scheduler selects process from the head of the queue.
A perfect real life example of FCFS scheduling is buying tickets at ticket counter.
3|Page
The average waiting time will be 18.75 ms
For the above given proccesses, first P1 will be provided with the CPU resources,
Hence, waiting time for P1 will be 0
P1 requires 21 ms for completion, hence waiting time for P2 will be 21 ms
Similarly, waiting time for process P3 will be execution time of P1 + execution time for P2, which will be (21
+ 3) ms = 24 ms.
For process P4 it will be the sum of execution times of P1, P2 and P3.
4|Page
Swapping is a mechanism in which a process can be swapped temporarily out of main memory (or move) to secondary
storage (disk) and make that memory available to other processes. At some later time, the system swaps back the
process from the secondary storage to main memory.
Though performance is usually affected by swapping process but it helps in running multiple and big processes in
parallel and that's the reason Swapping is also known as a technique for memory compaction.
The total time taken by swapping process includes the time it takes to move the entire process to a secondary disk and
then to copy the process back to memory, as well as the time the process takes to regain main memory.
Let us assume that the user process is of size 2048KB and on a standard hard disk where swapping will take place has
a data transfer rate around 1 MB per second. The actual transfer of the 1000K process to or from memory will take
2048KB / 1024KB per second
= 2 seconds
= 2000 milliseconds
Now considering in and out time, it will take complete 4000 milliseconds plus other overhead where the process
competes to regain main memory.
b) Explain the structure of disk drive with suitable diagram.
Ans. In modern computers, most of the secondary storage is in the form of magnetic disks. Hence, knowing the
structure of a magnetic disk is necessary to understand how the data in the disk is accessed by the computer.
A magnetic disk contains several platters. Each platter is divided into circular shaped tracks. The length of the tracks
near the centre is less than the length of the tracks farther from the centre. Each track is further divided into sectors, as
shown in the figure.
Tracks of the same distance from centre form a cylinder. A read-write head is used to read data from a sector of the
magnetic disk.
The speed of the disk is measured as two parts:
Transfer rate: This is the rate at which the data moves from disk to the computer.
Random access time: It is the sum of the seek time and rotational latency.
5|Page
Seek time is the time taken by the arm to move to the required track. Rotational latency is defined as the time taken
by the arm to reach the required sector in the track.
Even though the disk is arranged as sectors and tracks physically, the data is logically arranged and addressed as an
array of blocks of fixed size. The size of a block can be 512 or 1024 bytes. Each logical block is mapped with a sector
on the disk, sequentially. In this way, each sector in the disk will have a logical address.
c) What is a file? Explain different attributes of file.
What is a file? Explain different attributes of file.
Ans. A file can be defined as a data structure which stores the sequence of records. Files are stored in a file system,
which may exist on a disk or in the main memory. Files can be simple (plain text) or complex (specially-formatted).
A file's attributes vary from one operating system to another but typically consist of these:
Name: Name is the symbolic file name and is the only information kept in human readable form.
Identifier: This unique tag is a number that identifies the file within the file system; it is in non-human-
readable form of the file.
Type: This information is needed for systems which support different types of files or its format.
Location: This information is a pointer to a device which points to the location of the file on the device where
it is stored.
Size: The current size of the file (which is in bytes, words, etc.) which possibly the maximum allowed size
gets included in this attribute.
Protection: Access-control information establishes who can do the reading, writing, executing, etc.
Date, Time & user identification: This information might be kept for the creation of the file, its last
modification and last used. These data might be useful for in the field of protection, security, and monitoring
its usage.
6|Page
Single level directory is simplest directory structure. In it all files are contained in same directory which make it easy
to support and understand.
A single level directory has a significant limitation, however, when the number of files increases or when the system
has more than one user. Since all the files are in the same directory, they must have the unique name . if two users call
their dataset test, then the unique name rule violated.
Advantages:
Since it is a single directory, so its implementation is very easy.
If files are smaller in size, searching will faster.
The operations like file creation, searching, deletion, updating are very easy in such a directory structure.
Disadvantages:
There may chance of name collision because two files can not have the same name.
Searching will become time taking if directory will large.
In this can not group the same type of files together.
A tree structure is the most common directory structure. The tree has a root directory, and every file in the system have
a unique path.
Advantages:
Very generalize, since full path name can be given.
Very scalable, the probability of name collision is less.
Searching becomes very easy, we can use both absolute path as well as relative.
Disadvantages:
Every file does not fit into the hierarchical model, files may be saved into multiple directories.
We can not share files.
7|Page
It is inefficient, because accessing a file may go under multiple directories.
RAID is available in different schemes, or RAID levels. The most commonly levels are RAID 0, 1, 5, 6, and 10.
Raid 0: Striping
Requiring a minimum of two disks, RAID 0 splits files and stripes the data across two disks or more, treating the
striped disks as a single partition. Because multiple hard drives are reading and writing parts of the same file at the
same time, throughput is generally faster.
RAID 0 does not provide redundancy or fault tolerance. Since it treats multiple disks as a single partition, if even one
drive fails, the striped file is unreadable. This is not an insurmountable problem in video streaming or computer
gaming environments where performance matters the most, and the source file will still exist even if the stream fails. It
is a problem in high availability environments.
RAID 1: Mirroring
RAID 1 requires a minimum of two disks to work, and provides data redundancy and failover. It reads and writes the
exact same data to each disk. Should a mirrored disk fail, the file exists in its entirety on the functioning disk. Once IT
replaces the failed desk, the RAID system will automatically mirror back to the replacement drive. RAID 1 also
increases read performance.
It does take up more usable capacity on drives, but is an economical failover process on application servers.
8|Page
c) What are differences between command line interface (CLI) and graphical user interface (GUI).
d) What is deadlock? What are the necessary condition for deadlock occurrence? Explain in detail.
Deadlock is a situation where a set of processes are blocked because each process is holding a resource and waiting for
another resource acquired by some other process.
Consider an example when two trains are coming toward each other on same track and there is only one track,
none of the trains can move once they are in front of each other. Similar situation occurs in operating systems when
there are two or more processes hold some resources and wait for resources held by other(s). For example, in the below
diagram, Process 1 is holding Resource 1 and waiting for resource 2 which is acquired by process 2, and process 2 is
waiting for resource 1.
9|Page
Deadlock can arise if following four conditions hold simultaneously (Necessary Conditions)
1. Mutual exclusion: A resource can be assigned to at most one process at a time (no sharing).
2. Hold and wait: A processing holding a resource is permitted to request another.
3. No preemption: A process must release its resources; they cannot be taken away.
4. Circular wait: There must be a chain of processes such that each member of the chain is waiting for a
resource held by the next member of the chain.
10 | P a g e
Ans. Hypervisor is a form of virtualization software used in Cloud hosting to divide and allocate the resources on
various pieces of hardware. The program which provide partitioning, isolation or abstraction is called virtualization
hypervisor. Hypervisor is a hardware virtualization technique that allows multiple guest operating systems (OS) to run
on a single host system at the same time. A hypervisor is sometimes also called a virtual machine manager(VMM).
Types of Hypervisor –
TYPE-1 Hypervisor: Hypervisor runs directly on underlying host system. It is also known as “Native
Hypervisor” or “Bare metal hypervisor”. It dose not require any base server operating system. It has direct
access to hardware resources. Examples of Type 1 hypervisors include VMware ESXi, Citrix XenServer and
Microsoft Hyper-V hypervisor.
TYPE-2 Hypervisor: A Host operating system runs on underlying host system. It is also known as ‘Hosted
Hypervisor”. Basically a software installed on an operating system. Hypervisor asks operating system to make
hardware calls. Example of Type 2 hypervisor include VMware Player or Parallels Desktop. Hosted
hypervisors are often found on endpoints like PCs.
Cloud Computing can be defined as delivering computing power( CPU, RAM, Network Speeds, Storage OS software)
a service over a network (usually on the internet) rather than physically having the computing resources at the
customer location.
Cloud computing is a general term for anything that involves delivering hosted services over the Internet.
These services are broadly divided into three categories: Infrastructure-as-a-Service (IaaS), Platform-as-a-Service
(PaaS) and Software-as-a-Service (SaaS).
Types of Clouds:
There are four different cloud models that you can subscribe according to business needs:
1. Private Cloud: Here, computing resources are deployed for one particular organization. This method is more
used for intra-business interactions. Where the computing resources can be governed, owned and operated by
the same organization.
2. Community Cloud: Here, computing resources are provided for a community and organizations.
3. Public Cloud: This type of cloud is used usually for B2C (Business to Consumer) type interactions. Here the
computing resource is owned, governed and operated by government, an academic or business organization.
4. Hybrid Cloud: This type of cloud can be used for both type of interactions - B2B (Business to Business) or
B2C ( Business to Consumer). This deployment method is called hybrid cloud as the computing resources are
bound together by different clouds.
13 | P a g e
2. As a multiprocessor, such as single instruction, multiple data stream (SIMD), which is usually used for vector
processing.
3. Multiple series of instructions in a single perspective, such as multiple instruction, single data stream (MISD),
which is used for describing hyper-threading or pipelined processors.
4. Inside a single system for executing multiple, individual series of instructions in multiple perspectives, such as
multiple instruction, multiple data stream (MIMD).
Details vary from platform to platform, but in general the following steps represent the boot process. When the
computer starts, the BIOS performs Power- On-Self-Test (POST) and initial device discovery and initialization, since
the OS’ boot process may rely on access to disks, screens, keyboards, and so on. Next, the first sector of the boot disk,
the MBR (Master Boot Record), is read into a fixed memory location and executed. This sector contains a small (512-
byte) program that loads a standalone program called boot from the boot device, such as a
SATA or SCSI disk. The boot program first copies itself to a fixed high-memory address to free up low memory for
the operating system.
b) Explain Android architecture with diagram.
Android is built on top of the standard Linux kernel, with only a few significant extensions to the kernel itself that will
be discussed later. Once in user space, however, its implementation is quite different from a traditional Linux
distribution and uses many of the Linux features you already understand in very different ways.
As in a traditional Linux system, Android’s first user-space process is init, which is the root of all other processes. The
daemons Android’s init process starts are different, however, focused more on low-level details (managing file systems
and hardware access) rather than higher-level user facilities like scheduling cron jobs. Android also has an additional
layer of processes, those running Dalvik’s Java language environment, which are responsible for executing all parts of
the system implemented in Java.
14 | P a g e
c) Explain using suitable diagram NTFS master file table and its attribute.
Each NTFS volume (e.g., disk partition) contains files, directories, bitmaps, and other data structures. Each volume is
organized as a linear sequence of blocks (clusters in Microsoft’s terminology), with the block size being fixed for each
volume and ranging from 512 bytes to 64 KB, depending on the volume size. Most NTFS disks use 4-KB blocks as a
compromise between large blocks (for efficient transfers) and small blocks (for low internal fragmentation). Blocks are
referred to by their offset from the start of the volume using 64-bit numbers.
The principal data structure in each volume is the MFT (Master File Table), which is a linear sequence of fixed-size
1-KB records. Each MFT record describes one file or one directory. It contains the file’s attributes, such as its name
and timestamps, and the list of disk addresses where its blocks are located. If a file is extremely
large, it is sometimes necessary to use two or more MFT records to contain the list of all the blocks, in which case the
first MFT record, called the base record, points to the additional MFT records.
15 | P a g e
1. Provide a complete open-source platform for mobile devices. The open-source part of Android is a bottom-to-top
operating system stack, including a variety of applications, that can ship as a complete product.
2. Strongly support proprietary third-party applications with a robust and stable API. As previously discussed, it is
challenging to maintain a platform that is both truly open-source and also stable enough for proprietary third-party
applications. Android uses a mix of technical solutions (specifying a very well-defined SDK and division between
public APIs and internal implementation) and policy requirements (through the CDD) to address this.
3. Allow all third-party applications, including those from Google, to compete on a level playing field. The Android
open source code is designed to be neutral as much as possible to the higher-level system features built on top of it,
from access to cloud services (such as data sync or cloud-to-device messaging APIs), to libraries (such as Google’s
mapping library) and rich services like application stores.
4. Provide an application security model in which users do not have to deeply trust third-party applications. The
operating system must protect the user from misbehavior of applications, not only buggy applications
that can cause it to crash, but more subtle misuse of the device and the user’s data on it. The less users need to trust
applications, the more freedom they have to try out and install them.
5. Support typical mobile user interaction: spending short amounts of time in many apps. The mobile experience tends
to involve brief interactions with applications: glancing at new received email, receiving and sending an SMS message
or IM, going to contacts to place a call, etc. The system needs to optimize for these cases with fast app launch and
switch times; the goal for Android has generally been 200msec to cold start a basic application up to the point of
showing a full interactive UI.
e) Explain user mode scheduling (UMS) in windows7.
However, in Windows 7 Microsoft added a facility called UMS (User-Mode Scheduling), which exposes the
distinction. UMS is similar to facilities used in other operating systems, such as scheduler activations. It can be used
to switch between user threads without first having to enter the kernel, providing the benefits of fibers, but with much
better integration into Win32—since it uses real Win32 threads.
The implementation of UMS has three key elements:
1. User-mode switching: a user-mode scheduler can be written to switch between user threads without entering the
kernel. When a user thread does enter kernel mode, UMS will find the corresponding kernel thread and
immediately switch to it.
2. Reentering the user-mode scheduler: when the execution of a kernel thread blocks to await the availability of a
resource, UMS switches to a special user thread and executes the user-mode scheduler so that a different user
thread can be scheduled to run on the current processor. This allows the current process to continue using the
current processor for its full turn rather than having to get in line behind other processes when one of its threads
blocks.
3. System-call completion: after a blocked kernel thread eventually is finished, a notification containing the results
of the system calls is queued for the user-mode scheduler so that it can switch to the corresponding user thread
next time it makes a scheduling decision.
f) Explain using suitable diagram the kernel structure of Linux operating system.
16 | P a g e
The kernel sits directly on the hardware and enables interactions with I/O devices and the memory management unit
and controls CPU access to them. At the lowest level, as shown in Fig. it contains interrupt handlers, which are the
primary way for interacting with devices, and the low-level dispatching mechanism. This dispatching occurs when an
interrupt happens. The low-level code here stops the running process, saves its state in the kernel process structures,
and starts the appropriate driver. Process dispatching also happens when the kernel completes some operations and it is
time to start up a user process again. The dispatching code is in assembler and is quite distinct from scheduling. Next,
we divide the various kernel subsystems into three main components.
The I/O component in Fig. 10-3 contains all kernel pieces responsible for interacting with devices and performing
network and storage I/O operations. At the highest level, the I/O operations are all integrated under a VFS (Virtual
File System) layer. That is, at the top level, performing a read operation on a file.
17 | P a g e