0% found this document useful (0 votes)
12 views6 pages

Final Exam - Solution

The document contains the final exam solutions for an Operating Systems course for the academic year 2023-2024, including multiple-choice questions and detailed problems related to file systems and standard I/O redirection. It provides answers to various questions about file allocation mechanisms, socket programming, disk scheduling policies, and system calls. Additionally, it includes explanations and calculations for problems involving file system implementations and process communication using pipes.
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)
12 views6 pages

Final Exam - Solution

The document contains the final exam solutions for an Operating Systems course for the academic year 2023-2024, including multiple-choice questions and detailed problems related to file systems and standard I/O redirection. It provides answers to various questions about file allocation mechanisms, socket programming, disk scheduling policies, and system calls. Additionally, it includes explanations and calculations for problems involving file system implementations and process communication using pipes.
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/ 6

Operating Systems

Final exam (Solution)


Academic year 2023-2024
_____________________________________________________________________________

Name and surname: ______________________________ NIU:____________________

Multiple-choice answers
Test A
1 2 3 4 5 6 7 8 9 10 11 12

D A D B D B D C D A A C

Multiple-choice questions (6 points)


Answer the following multiple-choice questions in the space at the top of the page using
CAPITAL letters. Correctly answered questions add 0.5 points, incorrectly answered questions
subtract 0.125 points, and unanswered questions neither add nor subtract (0 points). For each
question there is only one correct answer.

Question 1
In a file system, what is the main drawback of the contiguous allocation mechanism?
A) It suffers from external fragmentation B) It is difficult to accommodate changes to
the file (i.e., increase size)
C) The size of the file has to be declared when D) All of the above statements are drawbacks
it is created of the contiguous allocation mechanism

Question 2
The following system call prototype is used to create a socket:
int socket(int domain, int type, int protocol);
What is the correct way to create a connection-oriented socket that uses IPv4 as the family
address?
A) socket(AF_INET, SOCK_STREAM, 0); B) socket(AF_INET, SOCK_DGRAM, 0);
C) socket(AF_UNIX, SOCK_STREAM, 0); D) None of the above

Question 3
Assuming that no other system call related to files has been executed before (i.e., open or
close), what is the return value of the following call?
int fd = open(“file_a.txt”)
A) fd = 0 B) fd = 1
C) fd = 2 D) None of the above

Question 4
What is the disk scheduling policy that minimizes the seek time between consecutive I/O
operations regardless of the process priority?
A) FIFO B) SSTF
C) C-SCAN D) None of the above

Page 1 of 6
Operating Systems
Final exam (Solution)
Academic year 2023-2024
_____________________________________________________________________________

Question 5
There is a file named “file.txt” in the current directory. The file is owned by a user named
“esupt” that belongs to the group “esupt”. What is the command to allow the owner of the
file to read and write it, members of the “esupt” group to read and execute the file, and all
the remaining users of the system to only read the file?
A) chmod 645 file.txt B) chown 654 file.txt
C) chmod 564 file.txt D) None of the above

Question 6
Where is the information related to the file status flags (i.e., read or write) and the current
file offset stored?
A) The file descriptor entry in the process B) An entry in the open file table of the kernel
table
C) An entry in the vnode table of the kernel D) None of the above

Question 7
When creating the server side of a connection-oriented socket, what is the system call that
blocks until a client connects?
A) connect() B) listen()
C) bind() D) None of the above

Question 8
What is the RAID level that provides block-interleaved distributed parity and requires N+1
disks to operate?
A) RAID 5 B) RAID 6
C) RAID 10 D) None of the above

Question 9
There is a file named “file.txt” in the current directory that has a length of 1024 bytes. We use
the following system call to open the file in read-only and append mode:
fd = open(“file.txt”, O_RDONLY, O_APPEND)
Assuming that fd=3, how can we go back to the start of the file without closing it and opening
it again?
A) lseek(3, -1024, SEEK_CUR) B) lseek(3, 0, SEEK_SET)
C) lseek(3, 0, SEEK_CUR) D) Both A) and B) answers are corrrect, but
answer C) is not

Question 10
When implementing communications between hosts with different endianness using sockets,
what is the proper call to convert a 4-byte variable before sending it?
A) htons() B) ntohs()
C) htonl() D) None of the above

Page 2 of 6
Operating Systems
Final exam (Solution)
Academic year 2023-2024
_____________________________________________________________________________

Question 11
In a file system that implements chained allocation, which of the following statements is
false?
A) It increases the read and write B) It allows files to grow and shrink easily,
performance thanks to allowing sequential since they can be added or removed from the
access chain
C) It ensures that external fragmentation D) None of the statements is false
does not happen

Question 12
Consider a disk with an average seek time of 8 ms, rotation speed of 6000 rpm, 512-byte
sectors, and 1024 sectors per track. Suppose that we wish to read a file consisting of 256
kbytes (1 kbyte = 1024 bytes). What is the transfer speed (TS, Mbytes/second) if the blocks
are stored sequentially?
A) TS < 5 Mbytes/s B) 5 ≤ TS < 10 Mbytes/s
C) 10 ≤ TS < 15 Mbytes/s D) TS ≥ 15 Mbytes/s

Problems (4 points)
Answer the following problems explaining all the steps that you have followed to reach
your solution. Answers without proper justification will not receive any points.

Problem 1 (File system implementation, 2 points)


A computer system has a hard drive with a total size of 1Tbyte of space (= 1 TB * 1024 GB/TB *
1024 MB/GB * 1024 KB/MB * 1024 B/KB = bytes) and a block size of 1kbyte (=1024 bytes).

a) [0.5 points] If the operating system uses chained allocation to store files, what is the
minimum size of each block that has to be devoted to point to other blocks (i.e., address
size, in bits)? Based on the result in bits, how many bytes would you use for the pointer?
Take into consideration the worst case scenario, in which the first block has to point to
the last block in the disk.

If the hard drive has a capacity of 10244 bytes (=1Tbyte) and each block is 1024 bytes, then we
need to address a total of 10243 blocks (=10244/1024). To address 10243 blocks we need
log2(10243) = 30 bits for the addresses. Since we typically need the addresses to be a multiple of
8 bits (=1 byte), we would pick 32 bits = 4 bytes for the address size of a block pointer.

b) [0.5 points] If the operating system uses indexed allocation with superblocks that only
only contain direct pointers to data blocks (i.e., first level of indirection), what is the
maximum size of a file that can be stored?

If each block address pointer is 4 bytes long (see above section), with 1024 bytes/block we can
have a total of 1024/4 = 256 1st level pointers per block. If each 1st level pointer points to 1024
bytes of data, then a file can have a maximum size of 256 * 1024 = 256 kbytes of data. Hence,
the maximum file length using 1st level pointers is 256 kbytes.

c) [0.5 points] To increase the maximum size of individual files, the operating system now
implements superblocks with indirect pointers of first, second and third level. How

Page 3 of 6
Operating Systems
Final exam (Solution)
Academic year 2023-2024
_____________________________________________________________________________

would you split the assignment of pointers of first, second and third level in the
superblock to ensure that the file system can accomodate files of up to 12 Gbytes?
Assume that each pointer is 4 bytes.

The maximum file length is determined by the 3rd level pointers of the superblock. Each 3rd level
pointer points to 256 blocks of 2nd level pointers, which point to 256 blocks of 1st level pointers
that point to 1kbyte (1024 bytes) of data. If we have a files with a maximum size of 12 * 10243
bytes (=12 Gbytes) then we need x 3rd level pointers, which can be computed as:

x * 256 * 256 * 1024 = 12 * 10243 --> x = 12 * 10242 / 65536 = 192 3rd level pointers.

d) [0.5 points] Assume that the file system uses pointers of 4 bytes, and each superblock
has a split ratio of 32, 64 and 128 pointers of each level (first, second and third level
pointers). If we want to store a file that has a size of 24 Mbytes, how many pointers of
each type (i.e., first, second and third level) will be used?

We can compute the number of pointers used going step by step at each level of pointers:

1) We have 32 1st level pointers, which account for 32 * 1024 = 32768 bytes = 32 kbytes.
2) We have 64 2nd level pointers, which account for 64 * 256 * 1024 = 16384 kbytes = 16
Mbytes.
3) For a file size of 24 Mbytes we are still missing 24 – 16 = 8 Mbytes (minus 32 kbytes
that we will not consider, since it is a very small amount). How many 3rd level pointers
do we need to point to 8 Mbytes? Each 3rd level pointer can point to 256 2nd level
pointers, which point to 256 1st level pointers, which point to 1 kbyte (1024 bytes) of
data. That is, one 3rd level pointer points to 256 * 256 * 1024 = 67108864 bytes =
65536 kbytes = 64 Mbytes of data. Hence, we will only need one 3rd level pointer. Of
that 3rd level pointer, we know that each 2nd level pointer points to 256 kbytes of data
(256 pointers x 1 kbyte of data per pointer). Hence, if we need to address 8 Mbytes =
8192 kbytes and each 2nd level pointer can hold 256 kbytes of data, we will need
8192/256 = 32 2nd level pointers.
4) That is, to address 24 Mbytes of data we need 32x1st level pointers, 64x2nd level
pointers and 1x3rd level pointers. Of that 3rd level pointer we will only use 32x2nd level
pointers, each pointing to 1 kbyte of data. In summary:
32 x 1kbyte + 64 x 256 x 1 kbyte + 1x (32x256 x 1 kbyte) = 24608 kbytes = 24.03125
Mbytes ≈ 24 Mbytes (since we are counting the 32 kbytes addressed by 1st level
pointers).

Page 4 of 6
Operating Systems
Final exam (Solution)
Academic year 2023-2024
_____________________________________________________________________________

Problem 2 (Standard I/O redirection, 2 points)


Consider the following source code that uses processes, pipes and files:

...
pipe(fd);
pid1 = fork();
if (pid1 != 0) {
pid2 = fork();
if (pid2 != 0) {
close(fd[0]); close(fd[1]);
while (1);
}
else {
close(0); dup(fd[0]);
close(fd[0]); close(fd[1]);
execv("programa2", "programa2", NULL);
}
}
else {
close(1); dup(fd[1]);
close(fd[0]); close(fd[1]);
execv("programa1", "programa1", NULL);
}

Assuming that all system calls are executed successfully, answer the following questions with
proper justification:

a) [0.5 point] Considering the standard input and the standard output of program1 and
program2, respectively, what is the main functionality that the source code implements?

The program implements a pipe where the output of program1 is redirecteed to the input of
program2. The pipe is created by the parent program, which is then inherited by each child. The
parent closes both ends of the pipe. After that, each child closes the reading or writing end of
the pipe before executing each respective program using the execv system call. Hence, the
standard output of program1 is transparently forwarded by the operating system to the
standard input of program2.

b) [0.5 points] Considering program1 and program2, what is the equivalent bash command
that implements the same source code functionality?

The bash command that performs the same functionality is “program1 | program2“.

Page 5 of 6
Operating Systems
Final exam (Solution)
Academic year 2023-2024
_____________________________________________________________________________

c) [1 point] Expalin how does the source code implement the functionality in terms of the pipe,
fork, close and dup system calls. Show the file descriptor tables of the parent and the
children at each step.

As explained in the last slide (40) of the chapter devoted to the filesystem, the code performs
the following operation:

1) The parent creates a pipe and two children that inherit the standard input and output
channels and the pipe.
2) The first child closes the standard output (1) and redirects its standard output to the
pipe write channel. It also closes the read and write ends of the pipe. Then it calls the
execv system call to replace the current program.
3) The second child closes the standard input (1) and redirects its the pipe output to the
standard input. It also closes the read and write ends of the pipe. Then it calls the
execv system call to replace the current program.
4) Effectively, the output of the program executed by the first child will be redirected to
the input of the program executed by the second child without them noticing. This is
all possible since children inherit the file table from their parent.
5) Remember that this all works because the dup system call uses the first available entry
in the process open file table when executing. Hence, the read side of the pipe is
assigned to the standard input of the second process. Similarly, the the write side of
the pipe is assigned to the standard output of the first process.

Page 6 of 6

You might also like