Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

1.

222 BINARY –> 222-128 = 94 – 64 = 30 – 16 = 14 – 8 = 6 – 4 = 2 – 2 = 0


11011110
HEX -> 1101 = 13 = D 1110 = 14 = E
DE

721 BINARY -> 721-512= 209 – 128 = 81 – 64 = 17 – 16 = 1 – 1 = 0

1011010001

HEX -> 0010 = 2 1101 = D 0001 = 1

2D1

1345 BINARY -> 1345 – 1024 = 321 – 256 = 65 – 64 = 1 – 1 = 0

10101000001

HEX -> 0101 = 5 0100 = 4 0001 = 1

541

1620 BINARY -> 1620 – 1024 = 596 – 512 = 84 – 64 = 20 – 16 = 4 – 4 = 0

11001010100

HEX -> 0110 = 6 0101 = 5 0100 = 4

654

1339 BINARY -> 1339 – 1024 = 315 – 256 = 59 – 32 = 27 – 16 = 11 – 8 = 3 – 2 = 1 – 1 = 0

10100111011

HEX -> 0101 = 5 0011 = 3 1011 = B

53B

2. A monolithic system OS is where the whole OS operates solely within the kernel space,
meaning file, memory, process, and device management all take place within the kernel
space. This means it is very limited in its modularity, meaning adding anything to it would
require many changes to be done to other parts of it, same with any updates. It would
however, have very good performance as it is all one code, same for memory, as it would
not use very much.
A layered OS would mean that user and system operations are separated, with user software
operations being handled at the top layers, and system layers at the bottom. This, while making it so
that performance may be a bit worse due to inter-layer communication and would require more
memory, means that new features can be easily added as the system is already programmed in a
modular manner, with any updates and such being easily integrated. This also means that security
would be tighter as each layer is isolated, meaning the system is safer.

3. NOT (A OR B) AND (NOT C OR D)

A B C D A∨B ¬C ¬(A ∨ B) ¬C∨D ¬(A ∨ B) ∧ (¬C ∨ D)


1 1 1 1 1 0 0 1 0
1 1 1 0 1 0 0 1 0
1 1 0 1 1 1 0 1 0
1 1 0 0 1 1 0 1 0
1 0 1 1 1 0 0 1 0
1 0 1 0 1 0 0 0 0
1 0 0 1 1 1 0 1 0
1 0 0 0 1 1 0 1 0
0 1 1 1 1 0 0 1 0
0 1 1 0 1 0 0 0 0
0 1 0 1 1 1 0 1 0
0 1 0 0 1 1 0 1 0
0 0 1 1 0 0 1 1 1
0 0 1 0 0 0 1 0 0
0 0 0 1 0 1 1 1 1
0 0 0 0 0 1 1 1 1

4. Kernel controls the communication between hardware and software, it has direct access to
the CPU, disk, and RAM. It is responsible for device drivers, security, memory management
and process scheduling.
The shell on the other hand is a user interface for interacting with the OS. It has restricted
access to hardware resources and relies on the kernel to perform the operations. The user
can, through the shell, execute commands, manipulate files, and run programs.
5. Here’s the program:

#include <iostream>
#include <ctime>
#include <cstdlib>

void printArray(int arr[], int size) {


for (int i = 0; i < size; i++) {
std::cout << "Address of arr[" << i << "] = " << &arr[i] << std::endl;
std::cout << "Value of arr[" << i << "] = " << arr[i] << std::endl;
}
}

void fillArray(int (&arr)[100]) {


srand(time(0));
for (int i = 0; i < 100; i++) {
arr[i] = rand() % 100; // generate a random number between 0 and 99
}
}

int main() {
int arr[100];
fillArray(arr);
printArray(arr, 100);

int* p = arr;
std::cout << "Address of array arr = " << p << std::endl;

for (int i = 0; i < 100; i++) {


std::cout << "*(p + " << i << ") = " << *(p + i) << std::endl;
}

return 0;
}

6. A. RR P2 P1 P4 P5 P3 P3 P3, FCFS P2 P1 P4 P5 P3, SJF P2 P1 P4 P5 P3, Priority P2 P1 P4 P5 P3


B. FCFS (First-Come-First-Served):
P2: Turnaround Time = 2, Waiting Time = 0
P1: Turnaround Time = 6, Waiting Time = 2
P4: Turnaround Time = 14, Waiting Time = 6
P5: Turnaround Time = 24, Waiting Time = 14
P3: Turnaround Time = 40, Waiting Time = 24

SJF (Shortest Job First):


P2: Turnaround Time = 2, Waiting Time = 0
P1: Turnaround Time = 6, Waiting Time = 2
P4: Turnaround Time = 14, Waiting Time = 6
P5: Turnaround Time = 24, Waiting Time = 14
P3: Turnaround Time = 40, Waiting Time = 24

Priority:
P2: Turnaround Time = 2, Waiting Time = 0
P1: Turnaround Time = 6, Waiting Time = 2
P4: Turnaround Time = 14, Waiting Time = 6
P5: Turnaround Time = 24, Waiting Time = 14
P3: Turnaround Time = 40, Waiting Time = 24

Round Robin (with time quantum 4):


P2: Turnaround Time = 6, Waiting Time = 4
P1: Turnaround Time = 14, Waiting Time = 10
P4: Turnaround Time = 30, Waiting Time = 22
P5: Turnaround Time = 40, Waiting Time = 30
P3: Turnaround Time = 56, Waiting Time = 40
C. SJF has the least waiting time for most.

7. A. The maximum number of "C"s printed is 3, occurring when Process A runs three times.
B. Process B can run twice, printing "B" each time, before semaphore V becomes 0. So, the
maximum number of "B"s printed is 2.
C. Similarly, Process C can run twice, printing "D" each time, before semaphore W becomes
0. So, the maximum number of "D"s printed is 2.

8. Synchronization involves coordinating processes or threads to ensure a predictable


execution of tasks, within a system that operates concurrently. The primary purpose of
synchronization is to avoid scenarios where simultaneous events may interfere with one
another potentially resulting in errors or conflicting results. In Windows, various
mechanisms and APIs are designed to facilitate coordination between processes. Some of
them are Mutexes (Mutual Exclusion Objects), which provide mutual exclusion, meaning
only one process accessing a shared resource at once. Critical Sections are used to protect
shared data within a single process. Events are used for signaling between processes to aid
synchronization. For synchronization related to thread waiting and signaling, Windows
provides condition variables as part of the condition variable API. Condition variables allow
threads to wait for a condition to become true before proceeding. Windows handles
synchronization internally using kernel objects and synchronization primitives offered by the
Windows kernel. These methods guarantee that concurrent processes or threads can
interact with shared resources safely preventing data corruption or inconsistencies. Effective
synchronization is essential, for creating efficient multithreaded or multi process
applications, on the Windows system.

9. LRU -
Page 1: [1], Page Fault = 1
Page 2: [1, 2], Page Fault = 2
Page 3: [1, 2, 3], Page Fault = 3
Page 4: [4, 2, 3], Page Fault = 4
Page 2: [4, 2, 3], Page Fault = 4
Page 1: [1, 4, 3], Page Fault = 5
Page 5: [5, 4, 3], Page Fault = 6
Page 6: [6, 4, 3], Page Fault = 7
Page 2: [6, 4, 2], Page Fault = 8
Page 1: [1, 4, 2], Page Fault = 9
Page 2: [1, 2, 4], Page Fault = 10
Page 3: [3, 1, 2], Page Fault = 11
Page 7: [7, 1, 2], Page Fault = 12
Page 6: [7, 1, 6], Page Fault = 13
Page 3: [7, 3, 6], Page Fault = 14
Page 2: [7, 3, 2], Page Fault = 15
Page 1: [1, 3, 2], Page Fault = 16
Page 2: [1, 3, 2], Page Fault = 16
Page 3: [1, 3, 2], Page Fault = 16
Page 6: [6, 3, 2], Page Fault = 17

FIFO –
Page 1: [1], Page Fault = 1
Page 2: [1, 2], Page Fault = 2
Page 3: [1, 2, 3], Page Fault = 3
Page 4: [2, 3, 4], Page Fault = 4
Page 2: [3, 4, 2], Page Fault = 5
Page 1: [4, 2, 1], Page Fault = 6
Page 5: [2, 1, 5], Page Fault = 7
Page 6: [1, 5, 6], Page Fault = 8
Page 2: [5, 6, 2], Page Fault = 9
Page 1: [6, 2, 1], Page Fault = 10
Page 2: [2, 1, 2], Page Fault = 11
Page 3: [1, 2, 3], Page Fault = 12
Page 7: [2, 3, 7], Page Fault = 13
Page 6: [3, 7, 6], Page Fault = 14
Page 3: [7, 6, 3], Page Fault = 15
Page 2: [6, 3, 2], Page Fault = 16
Page 1: [3, 2, 1], Page Fault = 17
Page 2: [2, 1, 2], Page Fault = 18
Page 3: [1, 2, 3], Page Fault = 19
Page 6: [2, 3, 6], Page Fault = 20

Optimal –
Page 1: [1], Page Fault = 1
Page 2: [1, 2], Page Fault = 2
Page 3: [1, 2, 3], Page Fault = 3
Page 4: [1, 2, 3], Page Fault = 3
Page 2: [1, 2, 3], Page Fault = 3
Page 1: [1, 2, 3], Page Fault = 3
Page 5: [5, 2, 3], Page Fault = 4
Page 6: [5, 6, 3], Page Fault = 5
Page 2: [5, 6, 2], Page Fault = 6
Page 1: [5, 6, 2], Page Fault = 6
Page 2: [5, 6, 2], Page Fault = 6
Page 3: [5, 6, 3], Page Fault = 7
Page 7: [5, 6, 7], Page Fault = 8
Page 6: [5, 6, 7], Page Fault = 8
Page 3: [5, 6, 7], Page Fault = 8
Page 2: [5, 6, 7], Page Fault = 8
Page 1: [5, 6, 7], Page Fault = 8
Page 2: [5, 6, 7], Page Fault = 8
Page 3: [5, 6, 7], Page Fault = 8
Page 6: [5, 6, 7], Page Fault = 8

The ranking is Optimal (8), LRU (17), FIFO (20)

10. First-Fit:
P1: Block2
P2: Block5
P3: Block3
P4: Block1
P5: Block1

Best-Fit:
P1: Block2
P2: Block5
P3: Block4
P4: Block1
P5: Block4

Worst-Fit:
P1: Block2
P2: Block5
P3: Block4
P4: Block1
P5: Block4

11. Windows and Linux are different in many aspects such as:
Kernel Architecture – Linux is monolithic, where all services run in the same space, with
device drivers and core system services making part of it. In Windows, both monolithic and
microkernel are used. Core services such as process and memory management run in kernel,
while device drivers and subsystems run in user mode.

UI –
Linux usually uses a GUI, but it can also be just text based. The default shell is BASH.
Windows on the other hand has a GUI mainly – start menu and such, with the CMD and PS
for shell.

File System –

Linux uses system files such as ext4, xfs and btrfs, using the FHS hierarchy. Windows on the
other hand uses NTFS, with FAT32 and exFAT also being supported.
Process Management –
Linux follows a multi-process, multi-threaded model where processes can use multiple
threads. It has a priority based scheduling algorithm for management, similarly to Windows.

Memory Management –
Linux has virtual memory management, with support for demand paging, memory mapping
and shared memory, using techniques such as copy-on-write and memory overcommitment.
Windows also uses these techniques but includes AWE for large memory support.

Security –
Linux follows DAC (Discretionary Access Control) where the owner controls all. Windows
uses both DAC and MAC (Mandatory Access Control) through its Security Descriptor
Definition Language (SDDL) and control lists (ACLs).

Device/Driver Management –
Linux has a modular driver model, where drivers are loaded into modules into the kernel at
runtime. Devices are managed through the /dev directory. Windows uses a layered driver
model, with the drivers being classified into kernel and user mode drivers. Device
management is done through the Device Manager and Registry.

Open/Closed Source –
Linux is fully open source, which is why there are many different distros, whilst Windows is
fully proprietary, with different versions being produced by Microsoft itself.

You might also like