Os Assignment 1 Answer Key
Os Assignment 1 Answer Key
Even Semester
OPERATING SYSTEMS
1. Explain in detail the types of systems calls provided by a typical operating system.
System calls are the interface between a user application and the kernel of the operating system. They
provide a mechanism for user-level programs to request services or resources from the operating system. These
services generally involve interaction with hardware, file systems, processes, memory, networking, and other
system components.
Here’s a detailed breakdown of the main types of system calls typically provided by an operating
system:
Process control system calls are used to manage processes, including their creation, termination, and
synchronization. These are fundamental for multitasking and process management.
fork(): Creates a new process by duplicating the calling process. The new process is a child of the
calling process.
exec(): Replaces the current process's memory space with a new program. This allows a process to load
and execute a different program.
exit(): Terminates the calling process and returns an exit status to the operating system.
wait(): Causes the parent process to wait for the termination of a child process. It can collect the exit
status of the child process.
getpid(): Returns the process ID (PID) of the calling process.
getppid(): Returns the parent process ID (PPID) of the calling process.
nice(): Adjusts the priority of the calling process.
kill(): Sends a signal to a process, usually to terminate it or notify it of an event.
File management system calls provide services for creating, deleting, reading, writing, and manipulating files
and directories.
open(): Opens a file or device for reading, writing, or both. It returns a file descriptor that identifies the
opened file.
read(): Reads data from a file into a buffer.
write(): Writes data from a buffer to a file.
close(): Closes an open file descriptor, freeing associated resources.
unlink(): Deletes a file from the file system.
mkdir(): Creates a new directory.
rmdir(): Removes an empty directory.
rename(): Renames or moves a file or directory.
lseek(): Moves the file pointer within an open file.
stat(): Retrieves information about a file (e.g., size, permissions, and modification time).
chmod(): Changes the permissions of a file or directory.
chown(): Changes the ownership of a file or directory.
These system calls allow programs to allocate, deallocate, and manage memory resources.
brk(): Changes the end of the data segment, which is used to manage the heap memory. It’s used for
dynamic memory allocation.
sbrk(): Adjusts the program’s data space (heap) by a specified amount.
mmap(): Maps files or devices into memory. It can also allocate memory regions that can be used for
various purposes like inter-process communication or memory-mapped file I/O.
munmap(): Unmaps a region of memory that was previously mapped using mmap().
malloc()/free(): (in higher-level libraries, though these eventually translate into system calls) Allocate
and free memory dynamically.
Device management system calls provide a means for programs to interact with hardware devices, such as disks,
keyboards, and network interfaces.
ioctl(): Performs device-specific input/output operations. It's used to configure or query device settings.
read(): As mentioned above, it reads data from a device, like a disk or network interface.
write(): As mentioned above, it writes data to a device.
open(): Used to open a device, such as a disk or terminal device, much like opening a file.
close(): Closes a device descriptor, much like closing a file.
These system calls are used for retrieving system information or managing resources.
IPC system calls enable processes to communicate with each other and synchronize their execution.
pipe(): Creates an inter-process communication channel (a pipe) that allows one process to send data to
another.
shmget()/shmat(): Creates and attaches shared memory segments for communication between
processes.
msgget()/msgsnd()/msgrcv(): Used for message passing in a message queue.
semget()/semop(): Used for creating and managing semaphores to synchronize process activities.
mmap(): As mentioned, can also be used for memory-mapped communication between processes.
These system calls are related to managing network communication, typically through socket programming.
The Operating System (OS) is the software that acts as an intermediary between the hardware and the
applications running on a computer. It provides a user-friendly environment and enables efficient management
of hardware and software resources. The basic functions of an OS can be grouped as follows:
1. Process Management
Process Creation and Termination: The OS is responsible for creating processes (programs in
execution) and terminating them when they are finished.
Scheduling: The OS schedules processes for execution on the CPU based on priority, time slices, and
other criteria. It ensures that multiple processes can run concurrently on multi-core processors or time-
sharing systems.
Process Synchronization and Communication: It manages synchronization and communication
between processes (e.g., through semaphores, shared memory, message passing, etc.).
2. Memory Management
Allocation and Deallocation: The OS manages the allocation of memory to various processes and
ensures that they do not interfere with each other’s memory.
Virtual Memory: It uses techniques like paging and segmentation to create the illusion of a larger
memory space than what physically exists. This is done by swapping data between physical memory
(RAM) and disk storage.
Memory Protection: It ensures that one process cannot access or modify the memory of another
process without permission, thereby preventing data corruption or security issues.
File Storage and Retrieval: The OS manages the file system, providing mechanisms for storing,
retrieving, naming, and organizing files on storage devices like hard drives or SSDs.
Access Control: It enforces file permissions and security to ensure that only authorized users can read
or modify specific files.
Directory Management: It manages the hierarchy of directories (folders) and the metadata associated
with files.
4. Device Management
Device Drivers: The OS manages hardware devices (e.g., printers, keyboards, hard drives) through
device drivers, which abstract the hardware interface and allow user applications to interact with them
without needing to know the details of the hardware.
Input/Output (I/O) Operations: It provides a standard interface for performing input/output
operations on devices, ensuring that devices can be used by multiple processes without conflicts.
Resource Allocation: It allocates and deallocates devices to processes, ensuring fair use and
minimizing conflicts.
Authentication and Authorization: The OS ensures that users are properly authenticated (e.g., via
passwords) and authorized to access certain resources (e.g., files, memory, devices).
Encryption and Data Integrity: The OS provides security mechanisms such as encryption and
integrity checks to protect sensitive data from unauthorized access or corruption.
Auditing and Monitoring: It tracks user activities and system events to detect and prevent malicious
or suspicious actions.
Direct Memory Access (DMA) is a feature that allows certain hardware subsystems (such as disk controllers,
sound cards, or network interfaces) to access the system's memory directly, bypassing the CPU. This improves
data transfer speeds and reduces the load on the processor.
Data Transfer: DMA enables direct transfer of data between I/O devices (such as a hard drive or
network card) and the main memory without involving the CPU, which allows faster and more efficient
data movement.
High-Speed Data Movement: DMA allows large blocks of data to be moved quickly between
memory and peripheral devices, reducing the need for the CPU to manage each byte of data transfer.
2. CPU Offloading
Minimizing CPU Intervention: Normally, the CPU controls all data transfers, which consumes CPU
cycles. With DMA, the CPU can offload these data transfer tasks, freeing it up to perform other
computations while data is being moved in the background.
Efficiency: By offloading repetitive data transfer operations (such as copying data to/from I/O
devices), DMA increases the overall efficiency of the system.
3. Interrupt Management
Interrupt-Driven Transfers: After a DMA transfer completes, the DMA controller sends an interrupt
to the CPU to inform it that the data transfer is finished. This allows the CPU to process the data once it
has been fully transferred without needing to be involved in the data movement process.
Control Signals: The DMA controller manages the necessary control signals for initiating and
managing the transfer, including when to read or write data from memory or peripheral devices.
4. Memory Addressing
Source and Destination Addresses: DMA uses memory addresses to determine where to read data
from and where to write data to. The addresses are typically set by the CPU before the transfer begins,
and the DMA controller manages the actual data transfer.
Burst Mode and Cycle Stealing: DMA supports various modes of data transfer, such as:
o Burst Mode: DMA transfers all the data in a single burst, locking out the CPU until the
transfer is complete.
o Cycle Stealing: The DMA controller steals one bus cycle at a time, allowing the CPU to
continue processing while the DMA transfer happens in the background.
Error Checking: Some DMA controllers incorporate error checking and correction mechanisms to
ensure that data is transferred correctly between devices and memory.
Data Buffering: To handle variations in transfer speed between the source and destination, DMA
controllers often use buffers (temporary storage areas) to hold data before it is moved to its final
destination.
3. List the various services provided by operating systems.
Operating systems (OS) provide a variety of services that enable the effective use of computer
hardware and facilitate the execution of user applications. These services are essential for system management,
resource allocation, and providing a stable interface for users and programs. Here’s a list of the various services
typically provided by an operating system:
Process Creation and Termination: OS enables the creation of new processes and their termination
when they are no longer needed.
Scheduling: It schedules processes for execution, ensuring that each process gets the necessary CPU
time according to priority, time slice, or other scheduling algorithms.
Inter-process Communication (IPC): Provides services for communication between processes,
allowing them to send and receive data, synchronize their actions, and share information.
Process Synchronization: Ensures that processes operate in a coordinated manner without causing
conflicts, typically using semaphores, mutexes, or other synchronization tools.
Process Control: OS provides system calls for controlling process behavior (e.g., pausing, resuming,
or killing processes).
Memory Allocation: The OS allocates memory to processes as needed and ensures efficient use of
memory resources.
Virtual Memory: Provides the illusion of a larger memory space than physically available by
swapping data in and out of physical memory (RAM) and disk storage.
Memory Protection: Prevents processes from accessing memory locations allocated to other
processes, ensuring data integrity and security.
Memory Deallocation: Frees up memory that is no longer needed, such as when a process terminates
or releases memory.
File Creation and Deletion: The OS allows the creation, modification, and deletion of files.
File Access and Management: OS manages access to files (read/write) and organizes files into
directories, making them easier to retrieve and manage.
File Permissions and Security: Ensures that only authorized users or processes can access specific
files, and enforces permissions such as read, write, and execute.
File and Directory Organization: Provides a hierarchical structure for organizing files and directories
on storage devices.
File I/O Operations: Facilitates reading from and writing to files using system calls.
Device Drivers: OS provides drivers that enable the communication between software and hardware
devices (e.g., printers, storage devices, network interfaces).
Device Control: Manages I/O operations between the CPU and hardware devices, ensuring efficient
data transfers.
Device Allocation and Deallocation: The OS assigns devices to processes and releases them when no
longer needed.
Interrupt Handling: Responds to interrupts from hardware devices, allowing the OS to react to events
like user input, hardware faults, or completion of I/O operations.
User Authentication: The OS verifies the identity of users through mechanisms like passwords,
biometrics, or smart cards.
Authorization and Access Control: Ensures that users can only access resources (files, devices, etc.)
that they are authorized to use, based on permissions and access control lists.
Data Encryption: OS can provide encryption services for protecting sensitive data stored on disk or
transmitted over networks.
Audit and Monitoring: Tracks and logs system activities to detect and prevent unauthorized access,
malicious behavior, or system misuse.
Malware Protection: Includes services for detecting and mitigating viruses, worms, and other
malicious software.
6. Networking Services
Network Communication: The OS provides services for data transmission over local or wide-area
networks using protocols like TCP/IP.
Socket Interface: Enables network communication between processes, either on the same system or
over a network, through APIs like sockets.
Network Resource Management: Manages network interfaces, assigns IP addresses, and ensures
efficient use of network resources like bandwidth.
Remote Access and File Sharing: OS supports protocols such as SSH, FTP, and NFS, allowing users
to access remote systems and share files over the network.
CPU Scheduling: Allocates CPU time to processes based on scheduling policies (e.g., round-robin,
priority-based, etc.).
Disk Scheduling: Manages access to disk resources, deciding the order in which processes access files
to minimize wait time and optimize performance.
Resource Allocation and Deallocation: The OS allocates resources like CPU cycles, memory, and
devices to processes and releases them when they are no longer needed.
Load Balancing: On multi-core or multi-processor systems, the OS distributes processes and threads
across processors to maximize performance and prevent bottlenecks.
Performance Monitoring: The OS tracks system performance, including CPU usage, memory usage,
and I/O operations, to ensure optimal system operation.
Resource Optimization: It makes decisions about how resources (e.g., memory, CPU time) should be
allocated to maximize efficiency and minimize resource wastage.
Fault Detection and Recovery: The OS detects system faults and implements recovery mechanisms
(e.g., restarting services, rolling back changes) to ensure the system continues to operate smoothly.
Boot Process Management: The OS is responsible for the initial boot-up process, loading system files,
initializing hardware, and starting core services when the computer is powered on.
System Configuration: Configures hardware and software during startup, including loading necessary
drivers, services, and background processes.
System Clock: The OS provides access to the system clock, allowing programs to retrieve the current
date and time.
Time Management: Services for scheduling tasks, alarms, and timers that rely on the passage of time
(e.g., periodic tasks, timeouts).
4. Consider the following set of processesI with the length of the CPU – burst time in given ms :
Given Data:
P1 8 0 3
P2 4 1 2
P3 9 2 1
P4 5 3 5
P5 3 4 4
1. First-Come-First-Serve (FCFS):
In FCFS, processes are executed in the order in which they arrive. The process that arrives first is executed first.
Process Arrival Time Burst Time Completion Time Turnaround Time (TAT) Waiting Time (WT)
P1 0 8 8 8-0=8 8-8=0
P2 1 4 12 12 - 1 = 11 11 - 4 = 7
P3 2 9 21 21 - 2 = 19 19 - 9 = 10
P4 3 5 26 26 - 3 = 23 23 - 5 = 18
Process Arrival Time Burst Time Completion Time Turnaround Time (TAT) Waiting Time (WT)
P5 4 3 29 29 - 4 = 25 25 - 3 = 22
In SJF, processes with the shortest burst time are executed first. If two processes have the same burst time, the
one that arrives first is chosen.
Process Arrival Time Burst Time Completion Time Turnaround Time (TAT) Waiting Time (WT)
P1 0 8 8 8-0=8 8-8=0
P2 1 4 11 11 - 1 = 10 10 - 4 = 6
P5 4 3 15 15 - 4 = 11 11 - 3 = 8
P4 3 5 20 20 - 3 = 17 17 - 5 = 12
P3 2 9 29 29 - 2 = 27 27 - 9 = 18
3. Priority Scheduling:
In Priority Scheduling, the process with the highest priority (lowest number) is executed first. If two processes
have the same priority, the one that arrives first is chosen.
Process Arrival Time Burst Time Completion Time Turnaround Time (TAT) Waiting Time (WT)
P1 0 8 8 8-0=8 8-8 = 0
P2 1 4 12 12 - 1 = 11 11 - 4 = 7
P3 2 9 21 21 - 2 = 19 19- 9 = 10
P4 3 5 29 29 - 3 = 26 26 - 5 = 21
Process Arrival Time Burst Time Completion Time Turnaround Time (TAT) Waiting Time (WT)
P5 4 3 24 24 - 4 = 20 20- 3 = 17
In Round Robin (RR), processes are executed in a circular fashion, with each process given a fixed time
quantum (2ms in this case). If a process's burst time exceeds the quantum, it is put back in the ready queue for
another round.
Process Arrival Time Burst Time Completion Time Turnaround Time (TAT) Waiting Time (WT)
P1 0 8 25 25 - 0 = 25 25 - 8 = 17
P2 1 4 14 14 - 1 = 13 13- 4 = 9
P3 2 9 29 29 - 2 = 27 27 - 9 = 18
P4 3 5 26 26 - 3 = 23 23- 5 = 18
P5 4 3 21 21 - 4 = 17 17 - 3 = 14