Exercise 1 (20 points). Autotest. Answer the quiz questions in the following table. Write the correct answer with its corresponding letter. For each 3 wrong answer, one correct answer will be subtracted as penalty. Nonanswered questions do not produce any penalty. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1. Which of the following alternatives has a page table with a size related to the physical memory? A) Two-level page table scheme B) Hashed page table C) Inverted page table D) None of these alternatives 2. Which are Readers-Writers problem conditions? A) Any number of readers may read from data area concurrently. B) Only a writer may modify information at once. C) During a write no reader may perform a request. D) All of the above. 3. Which kind of fragmentations might occur in paging and segmentation? A) In segmentation we might have internal fragmentation while in paging external fragmentation. B) In segmentation we might have external fragmentation while in paging internal fragmentation. C) We can have both internal and external fragmentation in paging but only internal in segmentation. D) We can have both internal and external fragmentation in segmentation but only internal in paging. 4. Choose the INCORRECT answer: In a mutex... A) lock(m) tries to block the mutex. If it is already locked, lock(m) unlocks it B) unlock(m) unblocks the mutex. If there are processes blocked in the mutex, one or several ones are unblocked C) lock(m) tries to block the mutex. If it is already locked, the calling thread is blocked D) lock(m) and unlock(m) are the only atomic operations for a mutex 5. In the concurrent use of files, the UNIX semantics specifies that: A) Each process uses a non-visible private copy that is not visible by the other processes. B) Each write produces a new file version. C) Concurrent file reads are the only allowed operations D) The file position pointer is not shared between processes. 6. The memory management unit (MMU)... 1
A) Is a hardware device that maps physical to virtual memory B) Provides hardware support to the OS memory management C) Is a component present only in Unix like systems D) None of the answers is correct 7. Select the correct answer, when a process is duplicated (fork): A) It duplicates open files table B) Shares intermediate table with i-nodes and positions C) A and B are correct D) A and B are incorrect 8. The process environment: A) There is not process environment but command shell environment. B) It is local the process and placed in the process stack. C) It defines the hardware context where the process is being executed. D) Defines if a process is environmentally friendly 9. The bit of user/kernel modes: A) Is provided by the operating system B) Provides the ability to distinguish when a process can run privileged instructions. C) Is changed only at the startup of the system D) None of the previous answers are correct 10. SIGILL, SIGALRM and SIGKILL are examples of a basic element in inter-process communication, which one? A) Exceptions B) Timers C) Signals D) Pipes 11. For the fork() system call in Linux, which of the following is true? A) The fork() process takes in an argument and returns a process ID. C) A child process is created but it does not execute the fork() function. D) When fork() is executed, an identical copy of its address space is created as well as its PCB. 12. Assume that we use the UNIX link service: int link(const char *existing, const char *new); Now, to link the file prueba.txt that is in /system with a file with the same name located in /users. Then: A) It is not possible to link two files with the same name. B) There are two files, remaining one as the original in /system and other, as the linked one in /users. C) There are two files, but they are indistinguishable because the OS does not record which one is the original one and which is the linked one. D) It is only possible to link directories. 2
13. An operating system is activated in response to: A) A service request from a process B) An interrupt from a peripheral C) A hardware exception D) All the above. 14. Search time corresponds to: A) The time taken for the replacement algorithm to select a page when a page fault occurs. B) The time it takes to transfer data on a disk. C) The average time it takes for the sector to be under the read / write disk. D) The time required for the disk heads to move to the appropriate cylinder. 15. When the software relocation of the memory addresses is being used: A) The program or a program fragment can be relocated at runtime. B) The protection between different processes is guaranteed. C) The program code in memory has independent logical space. D) All the answers are wrong. 3
Exercise 2 (30 points) Write a C program that creates the following processes: Parent Child1 ------> Child2 pipe Child 1 will read data form keyboard and will send it to Child2 through a pipe. Child2 displays the received message on the screen. The process execution will conclude when the Child1 receives the string "exit". Exercise 3. (30 points) Given a Producer-Consumer system where the producer generates information and increments a message counter. The consumer collects this information and then broadcast it and decrements the message counter. The processes do not interact with each other, except for control purposes. There are no mechanisms to store the produced information, thus it should be ensured strict alternation in the system. That is, when a producer generates information, it must wait until it has been collected by the Consumer before producing new information. The processes are coded according to the following pseudocode: procedure Producer is while (true) do generate_and_store; increase; end while; end procedure; procedure Consumer is while (true) do get_and_send; decrease; end while; end procedure; Increase and decrease operations are atomic and operate on the same variable. 4
Answer the following questions: Universidad Carlos III de Madrid 1. Modify the provided code to ensure strict alternation between producer and consumer processes. You can use semaphores and the generic wait and signal instructions. 2. In a second step, you have to modify the solutions to allow the producer to store messages and wait with them until the Consumer collects them. If there are producer and consumer processes waiting for being executed, the system must keep the strict alternation between them. Otherwise, the producer can pass its turn to another Producer process. Write the code implementation using shared integer variables and semaphores. Exercise 4. (20 points) Given the following small-size linked file system based on the File-Allocation Table (FAT): Block size: 1KB. The first 10 blocks (0 through 9) are reserved for filesystem, of which 3 are used to store filesystem information (SuperBlock) and for the filesystem boot (Boot). The remaining 7 blocks are used to store information of directories. The information of each directory occupies a block. Each entry has the following fields: filename extension with 64 bytes; metadata (user name, permissions, etc.) with 63 bytes; and starting block with 1 byte. A directory does not contain directories. Initially, the file system has two directories named (/documents and / bin) whose content is shown below: Directory: /documents Config.cf Doc.txt Metadata Metadata 18 11 Directory: /bin ls ps cd gcc Metadata Metadata Metadata Metadata 38 25 17 13 5
The FAT table only stores information related to the file data. The value -1 is used to encode the end of the file and 0 to indicate that the block is free. Below, the contents of the entire file system FAT table are shown. The upper index is the block number. The free block allocation policy for a new file is to first allocate the free blocks with the lowest identifier. FAT TABLE 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24-1 15 0-1 0 29 0 20-1 0 33 0 0 37 0 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 23 0 0 0 10 0-1 0-1 0 31 0 35-1 0 Considering this file system, answer the following questions. Justify your answer. 1. What is the total filesystem size? What is the filesystem effective capacity (the space in bytes that can be used to store file data)? 2. What is the maximum number of directories that the filesystem supports? How many files can be in each directory? 3. What are the files stored in the /bin directory? Briefly describes the functionality of each one of them. 4. Explain what blocks are uses to store information for the file /document/doc.txt. For the same file: In which block is the file data byte 2050 stored? 5. Show the changes in the file system that would involve creating a new file, named test.txt, with a size of 3 blocks in the /documents directory. 6. An important factor to improve the filesystem performance is to minimize the number of accesses to the filesystem data structures. This allows to reduce time while locating a particular data block. What are the drawbacks of this type of filesystem when accessing large files randomly (that is, not sequentially)? Do index-based files systems (such as UNIX-based i-nodes) have the same drawbacks? 6