You are on page 1of 5

DEPARTMENT OF COMPUTER ENGINEERING

The University of Lahore


1 - KM Defence Road, Lahore

================================================
Subject: Operating Systems Course Code: CS11303
Time Allowed: 01 Week Max Marks: 10
Examination: Assignment 01, Winter 22 Student Name: Usama Nasir Gill
Date: 17-03-2022 Reg. No.: BSC02183044
================================================
Note:
(i) Draw neat and clean labeled diagrams where necessary.
================================================

Question # 1: [CLO1, C2] (10)

a) Virtual Machines are computers running “guest operating system” inside virtual resources
(within host operating system). The Host OS runs on the physical hardware. The guest OS
uses hosts resources in a safe way. Discuss following in terms of Operating System.

i. Virtual Machines in detail :

A virtual machine (VM) is an operating system (OS) or application environment that


is installed on software, which imitates dedicated hardware. The end user has the
same experience on a VM as they would on dedicated hardware. A VM provides an
isolated environment for running its own OS and applications independently from the
underlying host system or from other VMs on that host. The VM's OS is commonly
referred to as the guest OS, and it can be the same as or different from the host OS or
the other VMs. In this way, a single computer can host multiple VMs, all running
different OSes and applications, without affecting or interfering with each other. The
VM is still dependent on the host's physical resources, but those resources are
virtualized and distributed across the VMs and can be reassigned as necessary,
making it possible to run different environments simultaneously, as well as
accommodate fluctuating workloads. A computer that hosts VMs requires specialized
software called a hypervisor. The hypervisor emulates the computer's CPU, memory,
hard disk, network and other hardware resources, creating a pool of resources that can
be allocated to the individual VMs according to their specific requirements. The
hypervisor can support multiple virtual hardware platforms that are isolated from
each other, enabling VMs to run Linux and Windows Server OSes on the same
physical host.

ii. Benefits and Features of Virtual Machines :

Benefits:
As the name suggests, a virtual machine (VM) is a virtual environment that simulates a physical
machine. VMs have their own central processing unit (CPU), memory, network interface, and
storage, but they are independent of physical hardware. Multiple VMs can coexist in a single
physical machine without collision, as long as the hardware resources are efficiently distributed.
VMs are implemented using software emulation and hardware virtualization.

A virtual machine is essentially a computer within a computer. VMs have several advantages:

• Lower hardware costs. Many organizations don’t fully utilize their hardware
resources. Instead of investing in another server, organizations can spin up virtual
servers instead.

• Quicker Desktop Provisioning and Deployment. Deploying a new physical server


often takes numerous time-consuming steps. However, with virtualized systems,
organizations can deploy new virtual servers quickly using secure pre-configured
server templates.

• Smaller Footprint. Utilizing virtualization reduces the office space needed to


maintain and extend IT capabilities while also freeing up desk space to support more
employees.

• Enhanced Data Security. Virtualization streamlines disaster recovery by replicating


your servers in the cloud. Since VMs are independent of the underlying hardware,
organizations don’t need the same physical servers offsite to facilitate a secondary
recovery site. In the event of a disaster, employees can be back online quickly with a
cost-effective backup and disaster recovery solution.

• Portability. It’s possible to seamlessly move VMs across virtual environments and
even from one physical server to another, with minimal input on the part of IT teams.
VMs are isolated from one another and have their own virtual hardware, making them
hardware-independent. Moving physical servers to another location is a more
resource-intensive task.

• Improved IT Efficiency. Many IT departments spend at least half of their time


managing routine administrative tasks, however with virtualization it’s possible to
partition one physical server into several virtual machines—administrators can
deploy and manage multiple operating systems at once from a single physical server.

Features:
1. Host system resources are shared among the various VMs. For example, if a host system
has 8GB memory where VMs are running, this amount will be shared by all the VMs,
depending upon the size of the allocation.

2. One of the best features of using Virtual machines is we can run multiple operating
systems/VMs in parallel on one host system.

3. The VMs are isolated from one another, thus secure from malware or threat from any other
compromised VM running on the same host.
4. The direct exchange of data and mutual influencing are prevented.

3. The transfer of virtual machines to another system can be implemented by simply


copying the VM data since the complete status of the system is saved in a few files.

6Virtual machines can be operated on all physical host systems that support the virtualization
environment used.

iii. Virtual Machine Apps:

Virtual Machine app, or VM app, is a program that simulates the virtual computing
environment. The virtual machine is created on a host operating system of a computer.
The VM app creates virtual CPU, storage, memory, network interface, and other
devices.

Examples of Virtual Machine Apps adapted to such hardware include KVM, VMware
Workstation, VMware Fusion, Hyper-V, Windows Virtual PC, Xen, Parallels Desktop for
Mac, Oracle VM Server for SPARC, VirtualBox and Parallels Workstation.

iv. How to setup Virtual Machine using step by step procedure:

Step 1: Prepare your computer for Virtualization. ...


Step 2: Install Hypervisor (Virtualization Tool) ...
Step 3: Import a Virtual Machine. ...
Step 4: Start the Virtual Machine. ...
Step 5: Using the Virtual Machine. ...
Step 6: Shut down the Virtual Machine.

b) Explain creation and termination coding of a separate process using

i. UNIX fork() system call

System call fork() is used to create processes. It takes no arguments and returns a process ID.
The purpose of fork() is to create a new process, which becomes the child process of the caller.
After a new child process is created, both processes will execute the next instruction following
the fork() system call. Therefore, we have to distinguish the parent from the child. This can be
done by testing the returned value of fork():

• If fork () returns a negative value, the creation of a child process was unsuccessful.
• fork () returns a zero to the newly created child process.
• fork () returns a positive value, the process ID of the child process, to the parent. The
returned process ID is of type pid_t defined in sys/types.h. Normally, the process ID is
an integer. Moreover, a process can use function getpid() to retrieve the process ID
assigned to this process.
Therefore, after the system call to fork(), a simple test can tell which process is the child. Please
note that Unix will make an exact copy of the parent's address space and give it to the child.
Therefore, the parent and child processes have separate address spaces.

Let us take an example to make the above points clear..

#include <stdio.h>
#include <string.h>
#include <sys/types.h>

#define MAX_COUNT 200


#define BUF_SIZE 100

void main(void)
{
pid_t pid;
int i;
char buf[BUF_SIZE];

fork();
pid = getpid();
for (i = 1; i <= MAX_COUNT; i++) {
sprintf(buf, "This line is from pid %d, value = %d\n", pid, i);
write(1, buf, strlen(buf));
}
}

ii. Win32 API

Win32 is the main set of Microsoft Windows APIs used for developing 32-bit
applications. These APIs are responsible for functions in the following categories:
Administration and Management - Install, configure, and service applications or systems
A process may be created in the system for different operations. Some of the events
that lead to process creation are as follows −

• User request for process creation


• System Initialization
• Batch job initialization
• Execution of a process creation system call by a running process

iii. Producer-Consumer problem:

The above three problems can be solved with the help of semaphores(learn more about
semaphores from here).

In the producer-consumer problem, we use three semaphore variables:


1. Semaphore S: This semaphore variable is used to achieve mutual exclusion
between processes. By using this variable, either Producer or Consumer will be
allowed to use or access the shared buffer at a particular time. This variable is
set to 1 initially.
2. Semaphore E: This semaphore variable is used to define the empty space in the
buffer. Initially, it is set to the whole space of the buffer i.e. "n" because the
buffer is initially empty.
3. Semaphore F: This semaphore variable is used to define the space that is filled
by the producer. Initially, it is set to "0" because there is no space filled by the
producer initially.
By using the above three semaphore variables and by using the wait () and signal
() function, we can solve our problem

You might also like