Operating system
Operating system
the
first question:
Operating Systems Examination (70 Marks)
Instructions: Answer all questions. Marks for each question are indicated in brackets.
1. Basic Concepts (15 Marks)
a) What is an Operating System? Give two examples of popular operating systems used on
personal computers. (5 Marks)
● Answer:
○ An Operating System (OS) is a foundational layer of software that manages
computer hardware and software resources. It acts as an intermediary between the
user and the hardware, providing essential services such as resource allocation
(CPU, memory, I/O devices), file management, and security. It creates an
environment where applications can run efficiently and effectively.
○ Two popular operating systems used on personal computers are:
■ Windows: Developed by Microsoft, Windows is widely used for its
user-friendly interface and extensive software compatibility. It supports a
broad range of applications, from productivity tools to gaming.
■ macOS: Developed by Apple, macOS is known for its stability, security, and
seamless integration with Apple hardware. It's popular among creative
professionals and users who prefer an intuitive interface.
b) Explain the difference between a process and a thread. Give a real-world example where
using threads can improve a program's performance. (10 Marks)
● Answer:
○ A process is an independent execution of a program, with its own dedicated
memory space, resources, and execution context. Each process operates in
isolation, meaning that if one process crashes, it typically doesn't affect other
processes.
○ A thread, on the other hand, is a lightweight sub-process that exists within a
process. Threads share the same memory space and resources as their parent
process, allowing them to communicate and share data more efficiently. Multiple
threads can execute concurrently within a single process, improving parallelism and
responsiveness.
○ Real-world example: A web server. When a web server receives multiple client
requests, it can create a separate thread for each request. This allows the server to
handle multiple requests simultaneously. For instance, while one thread is waiting
for a database query to complete, another thread can serve a static HTML page to
a different client. This concurrent execution of threads significantly improves the
server's throughput and responsiveness, resulting in a better user experience.
2. Memory and File Management (15 Marks)
a) Why is virtual memory useful? Imagine you have a computer with only 4GB of RAM but want
to run a program that requires 8GB. How does virtual memory help? (8 Marks)
● Answer:
○ Virtual memory is a memory management technique that allows a computer to
execute programs that require more memory than is physically available (RAM). It
creates an illusion of a larger memory space by using the hard drive as an
extension of RAM.
○ Virtual memory is useful because:
■ It enables the execution of larger programs that would otherwise exceed the
physical memory capacity.
■ It improves CPU utilization by allowing multiple processes to reside in
memory, even if their combined memory requirements exceed the physical
RAM.
■ It enhances memory protection by providing each process with its own virtual
address space, preventing processes from interfering with each other.
○ In the given scenario, where a computer has 4GB of RAM but needs to run an 8GB
program, virtual memory helps by:
■ Dividing the program into smaller units called pages.
■ Storing the less frequently used pages on the hard drive (swap space).
■ Loading only the necessary pages into RAM when they are needed.
■ When a page is needed that is not in ram, the OS swaps a page in RAM to
the hard drive, and loads the needed page into ram.
■ This process, called paging, allows the program to run, albeit potentially
slower due to the slower access speed of the hard drive compared to RAM.
b) What is a file system? Give two common types of file systems used in modern operating
systems and where they are commonly used. (7 Marks)
● Answer:
○ A file system is a method of organizing and storing files on a storage device (e.g.,
hard drive, SSD). It provides a structured way to access and manage files, including
creating, reading, writing, and deleting them. A file system defines how files are
named, stored, and retrieved.
○ Two common types of file systems:
■ NTFS (New Technology File System): Developed by Microsoft, NTFS is the
primary file system used in Windows operating systems. It supports
advanced features such as file compression, encryption, and access control
lists (ACLs), making it suitable for modern storage devices and security
requirements.
■ ext4 (Fourth Extended File System): Ext4 is a journaling file system used in
Linux operating systems. It's known for its reliability, performance, and
support for large file systems. Ext4 is widely used in servers, desktops, and
embedded systems running Linux.
3. Scheduling (15 Marks)
a) Imagine you have three tasks to complete: Task A (5 minutes), Task B (10 minutes), and Task
C (2 minutes). If you use a First-Come, First-Served (FCFS) scheduling method, in what order
will you complete the tasks? What about if you use Shortest-Job-Next (SJN)? (8 Marks)
● Answer:
○ FCFS (First-Come, First-Served): This scheduling algorithm executes tasks in the
order they arrive. If the tasks arrive in the order A, B, C, then they will be completed
in the same order: A, B, C. This algorithm is simple but can lead to long wait times
for short tasks if a long task arrives first.
○ SJN (Shortest-Job-Next): This algorithm schedules the task with the shortest
execution time first. In this case, the order would be C (2 minutes), A (5 minutes),
and then B (10 minutes). SJN minimizes the average waiting time for tasks, but it
requires knowing the execution time of each task in advance, which is not always
possible.
b) Explain the concept of Real-Time Operating System (RTOS) scheduling. Discuss the
differences between hard and soft real-time systems, and describe a scheduling algorithm
suitable for hard real-time systems, justifying your choice. (7 Marks)
● Answer:
○ Real-Time Operating System (RTOS) Scheduling: RTOS scheduling is designed
to ensure that tasks are completed within strict time constraints. The focus is on
predictability and meeting deadlines, rather than average throughput or fairness.
○ Hard vs. Soft Real-Time Systems:
■ Hard Real-Time Systems: In hard real-time systems, missing a deadline can
have catastrophic consequences. Tasks must complete within their deadlines,
without exception. Examples include flight control systems and medical
devices.
■ Soft Real-Time Systems: In soft real-time systems, missing a deadline is
undesirable but tolerable. Tasks should complete within their deadlines as
much as possible, but occasional misses are acceptable. Examples include
multimedia streaming and online gaming.
○ Scheduling Algorithm for Hard Real-Time Systems:
■ Rate Monotonic Scheduling (RMS): RMS is a static priority scheduling
algorithm suitable for hard real-time systems. It assigns priorities to tasks
based on their periods (the time interval between task executions). Tasks with
shorter periods are assigned higher priorities.
■ Justification: RMS is chosen because it is provably optimal for scheduling
periodic tasks in hard real-time systems. It guarantees that if a set of periodic
tasks is schedulable using any static priority algorithm, it is also schedulable
using RMS. RMS is predictable and ensures that critical tasks with short
periods are executed promptly, meeting their deadlines.
4. Deadlocks and I/O (15 Marks)
a) Explain a real-world scenario where a deadlock might occur (e.g., in a library or a restaurant).
(8 Marks)
● Answer:
○ Real-world scenario: A restaurant with two tables and two groups of diners. Group 1
needs table A and table B to dine. Group 2 also needs table A and table B.
■ Group 1 sits at table A, and Group 2 sits at table B.
■ Now, Group 1 is waiting for table B, which is held by Group 2, and Group 2 is
waiting for table A, which is held by Group 1.
■ Neither group can proceed, resulting in a deadlock. This is analogous to the
"hold and wait" and "circular wait" conditions for deadlocks in operating
systems.
b) What is a device driver, and why is it important for I/O operations? (7 Marks)
● Answer:
○ A device driver is a software program that enables the operating system to
communicate with a specific hardware device. It acts as a translator between the
OS and the device, converting general I/O commands from the OS into
device-specific commands that the hardware can understand.
○ Device drivers are crucial for I/O operations because:
■ They handle the low-level details of communicating with hardware devices,
which can vary significantly in their interfaces and protocols.
■ They abstract away the complexity of hardware interaction, allowing the OS
and applications to interact with devices