0% found this document useful (0 votes)
17 views

Revision en 2024

Revision for OS 232
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Revision en 2024

Revision for OS 232
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

REVISION

EXERCISES – OPERATING SYSTEM

1. Given the following code:


#include <stdio.h>
#include <unistd.h>
int main()
{
int i;
int n;
scanf("%d",&n);
printf("Hello! \n");

for(i=0;i<n;i++){
fork();
}
printf("Hello! \n");
return 0;
}

How many “Hello!” will be displayed onto the screen?


n= 2
n= 3
n= 4
2. Consider the following set of processes, with the length of the CPU-burst time
given in milliseconds:
Process Burst Time Arrival time
P1 10 3
P2 20 0
P3 2 3
P4 3 4
P5 5 2

a. Draw 3 Gantt charts illustrating the execution of these processes using FCFS,
SJF, SRTF and RR (quantum = 2) scheduling.
b. What is the turnaround time of each process for each of the scheduling
algorithms in part a?
3. Many CPU-scheduling algorithms are parameterized. For example, the RR
algorithm requires a parameter to indicate the time slice. Multilevel feedback
queues require parameters to define the number of queues, the scheduling
algorithms for each queue, the criteria used to move processes between queues,
and so on. These algorithms are thus really sets of algorithms (for example,
the set of RR algorithms for all time slices, and so on). One set of algorithms
may include another (for example, the FCFS algorithm is the RR algorithm with
an infinite time quantum). What (if any) relation holds between the following
pairs of algorithm sets?
a. Priority and SJF

b. Multilevel feedback queues and FCFS

c. Priority and FCFS

d. RR and SJF
4. A computer provides each process with 32768 bytes of address space divided
into pages of 4096 bytes.
a. How many page frames could a process be allocated?
b. A particular program has 3 segments: a text size of 11770 bytes, a data size of
10284 bytes, and a stack size of 9786 bytes. Will this program fit in the
address space?
c. If the page size were 512 bytes, would it fit?
Remember that a page may not contain parts of two different segments.
5. Given the following reference string:
021301401234
a. Show page faults occur during the processing of the reference scheme with
LRU and FIFO, OPTIMAL, CLOCK? Each process is allocated 3 empty page
frames.
b. Estimate the hit ratio for LRU policies in a pure demand paging system if the
TLB could contains 3 entries. Then compute the effective access time,
suppose TLB lookup takes 5 nano sec, and memory access time is 100 nano
sec.
6. Consider a system where the virtual memory page size is 2K (2048 bytes), and
main memory consists of 4 page frames. Now consider a process which requires
8 pages of storage. At some point during its execution, the page table is as shown
below:

Virtual page Valid Physical page a. List the virtual address


ranges for each virtual
0 (0->2k-1) No page.
1(2k – 4k-1) No b. List the virtual address
ranges that will result in a
2 Yes 1 page fault

3 No c. Give the main memory


(physical) addresses for each of
4 Yes 3 the following virtual addresses
(all numbers decimal):
5 No
(i) 8500, (ii) 14000, (iii) 5000,
6 Yes 0 (iv) 2100

7 Yes 2
7. Given the following code:
1: int main(int argc, char *argv[]) {
3: int a, e;
5: a = 10;
6: if (fork() == 0) {
7: a = a *2 ;
8: if (fork() == 0) {
9: a = a +1;
10: exit(2);
11: }
12: printf(" %d \n", a);
13: exit(1);
14: }
15: wait(&e);
16: printf("a: %d;e : %d \n", a, WEXITSTATUS(e));
17: return(0);
18: }

Give the number of processes generated when running this program and the
content display onto the screen for each process.
8. Choose the correct state transition.
a. new - ready - running - waiting - terminated
b. new - waiting - ready - running - terminated
c. new - ready - waiting - ready - running - terminated
d. new - ready - running - waiting - ready - running – terminated

9. There are two processes P0 and P1 in the system.


The variable turn is set to 0. The code for process P0 is as follows:

P0 P1
….. …..
while (turn != 0) { } /* Do while (turn != 1) { } /* Do nothing
nothing and wait. */ and wait. */
Critical Section /* . . . */ Critical Section /* . . . */
turn = 0; turn = 1;
…. ….

For P1, 0 is replaced by 1. Does this solution satisfy the mutual exclusion?

10. The following illustration is an incorrect use of


semaphores to solve the critical-section problem:
wait(mutex);
...
critical section
...
wait(mutex);
Explain why this is an example of a liveness failure.
11. Each process Pi, i = 0,1,2,3,……,9 is coded as follows.
P(mutex)
{Critical Section}
V(mutex)

The code for P10 is identical except that it uses V(mutex) instead of P(mutex).

V(mutex)
{Critical Section}
V(mutex)

What is the largest number of processes that can be inside the critical section at any
moment (the mutex being initialized to 1)?

12. Given the following code for P[i], i=0..3, initialize m[i]=1
wait (m[i]); wait(m[(i+1) mode 4]);

//critical section

release (m[i]); release (m[(i+1)mod 4]);

When executing these processes, what will happen?


13. Consider a logical address space of 64 pages of 1,024 words each, mapped onto
a physical memory of 32 frames.
a. How many bits are there in the logical address?
b. How many bits are there in the physical address?

14. Consider a computer system with a 32-bit logical address and 4-KB page size.
The system supports up to 512 MB of physical memory. How many entries are
there in each of the following?
a. A conventional, single-level page table
b. An inverted page table dựa trên số frames
15. Consider the page table for a system with 12-bit virtual and physical addresses
and 256-byte pages.

The list of free page frames is D, E, F (that is, D is at the head of the list, E is
second, and F is last). A dash for a page frame indicates that the page is not in
memory.
Convert the following virtual addresses to their equivalent physical addresses
in hexadecimal. All numbers are given in hexadecimal.
• 9EF
• 111
• 700
• 0FF
17. Suppose a computer has a file system for a 256MB disk, where each disk block
is 1MB.
a. If the OS for this computer uses a FAT, what is the smallest amount of
memory that could possibly be used for the FAT (assuming the entire FAT
is in memory)? Explain.
b. Given the following information:

1. File name 2. 1st block


3. toto.txt 4. 7
And the current content of FAT:

0 0 8

1 1 3

2 2 6

3 3 2

4 4 1

5 5 end-of-file

6 6 5

7 7 4

8 8 7

….. …..

List all possible block for the file toto.txt.


18. Suppose that on a computer, the OS uses i-nodes and each disk block is 4KB.
Assume that an i-node contains 12 direct block numbers (disk addresses) and the
block numbers for one indirect block, one double indirect block, and one triple
indirect block. Assume also that a block number is 4 bytes.
b. What is the largest possible file on that computer (assuming the disk is large
enough).
c. On this computer, suppose you wanted to create a new file of the maximum
size (that you computed for the answer a). How many free blocks on the disk
would there need to be in order to create that file?
d. How many pointers of this i-node would be used in order to create the file
toto.txt in the previous question?
19. Using bit vector/linked list/grouping (n=4)/counting method for free space
management of 30 disk blocks, we assume that 3, 6, 8, 9, 10, 11, 12, 13, 17, 18,
19, 25, 26, 27 are free blocks. How is free space managed?

20. Suppose that a disk drive has 2000 cylinders, numbered 0 to 1999. The drive is
currently serving a request at cylinder 950, and the previous request was at
cylinder 15. The queue of pending requests, in FIFO order, is: 86,1470, 913,
1774, 948, 1509, 1022,1750,130. Starting from the current head position, what
is the total distance (number of cylinders) that the disk arm moves to satisfy all
the pending requests for each of the following disk-scheduling algorithms
(FCFS, SSTF, SCAN, C-SCAN, LOOK, C-LOOK) ?

You might also like