OS Assignment 1
OS Assignment 1
OS Assignment 1
================================================
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.
================================================
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.
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.
• 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.
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.
6Virtual machines can be operated on all physical host systems that support the virtualization
environment used.
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.
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.
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
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));
}
}
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 −
The above three problems can be solved with the help of semaphores(learn more about
semaphores from here).