• Home
  • Home
  • Scoreboard
  • Scoreboard
  • Exam statistics
  • Exam statistics
  • Profile
  • Profile
  • Login.no
  • Login.no
  • Home
  • Home
  • Scoreboard
  • Scoreboard
  • Exam statistics
  • Exam statistics
  • Profile
  • Profile
  • Login.no
  • Login.no
  • BrowseStudy

    Courses

    + Add
    Edit
    / study

    Learning Material for IDATG2202

    This course allows examination aids, and is not a multiple choice based exam.

    Kont 2023 addrspace.pagetable (5%) Consider the following diagram where the incoming virtual address 8196 (decimal) is translated to the outgoing physical address 24580 (decimal). If the incoming virtual address is 12 (decimal), what will be the outgoing physical address (decimal)? 4096 4108 Gir page fault 12 8204 24588 8200 24592 24580 hwreview.assembly (3%) The following three lines of assembly code are in the wrong order (when reading from the top like we do when we read code). Move the lines to the right in such a way that they end up in the correct order. introproc.intro (9%) 1. (3%) How does the operating system "virtualize" the CPU (making it appear as multiple processes are running at the same time even if we have just one CPU core) ? Skriv ditt svar her 2. (3%) How does the operating system "virtualize" Memory (so multiple processes can access the same memory addresses without sharing those memory locations)? Skriv ditt svar her 3. (3%) How does the operating system "virtualize" storage of data on storage media like HDD, SSD, flash cards, etc.? Skriv ditt svar her Maks poeng: 9 (3%) How does the operating system "virtualize" the CPU (making it appear as multiple processes are running at the same time even if we have just one CPU core) ? By giving each process small time slices on the CPU, starting and stopping processes, sharing the CPU so fast that it appears as the processes run at the same time. (2%) How does the operating system "virtualize" Memory (so multiple processes can access the same memory addresses without sharing those memory locations)? By giving each process its own address space, which the operating system divides into pages and maps them in to separate page frames in the actual physical memory. (2%) How does the operating system "virtualize" storage of data on storage media like HDD, SSD, flash cards, etc.? By offering the abstraction of a "file" which the operating system with its drivers transfers onto the storage media which knows nothing about files and just stores data magnetically, optically, electronically, etc. syscalls.fork (10%) Write a C program that creates a new process (use the system call fork). The new process that is created should print "My PID is XYZ" and then make a system call to run /bin/date. XYZ should be the new process ID and it should be retrieved with a system call. (you do not need to include header files, just focus on the contents of main()) Skriv ditt svar her IDATG2202 Operativsystemer Aug 2023 Maks poeng: 10 16/20 1 Important to use fork() correctly by testing the return variable, and the candidate should know getpid and exec system calls. main() { int p; p=fork(); if(p==0) { printf("My PID is %d", getpid()); exec("/bin/date"); } } scheduling.mlfq (9%) 1. (5%) Explain how Multi-Level Feedback Queue (MLFQ) works by writing down the scheduling rules the algorithm is composed of (hint: there are ca five such rules dependent on the variant of MLFQ presented in the text book, any variant you answer is fine). 2. (4%) Why is MLFQ such a good scheduling algorithm? (in other words: which problems does MLFQ solve? what is the goal of MLFQ?) Skriv ditt svar her IDATG2202 Operativsystemer Aug 2023 Σ Format    Typical rules are: Rule 1: If Priority(A) > Priority(B), A runs (B doesn’t). Rule 2: If Priority(A) = Priority(B), A & B run in round-robin fashion using the time slice (quantum length) of the given queue. Rule 3: When a job enters the system, it is placed at the highest priority (the topmost queue). Rule 4: Once a job uses up its time allotment at a given level (regardless of how many times it has given up the CPU), its priority is reduced (i.e., it moves down one queue). Rule 5: After some time period S, move all the jobs in the system to the topmost queue. or other variations as long as they mention that CPU-intensive jobs are pushed down, but starvation is solved by sometimes moving them back up. from textbook: "MLFQ is interesting for the following reason: instead of demanding a priori knowledge of the nature of a job, it observes the execution of a job and prioritizes it accordingly. In this way, it manages to achieve the best of both worlds: it can deliver excellent overall performance (similar to SJF/STCF) for short- running interactive jobs, and is fair and makes progress for long-running CPU-intensive workloads" in other words, it achieves benefits of Shortest Job First without causing starvation, and it takes into account the behaviour of the process without requiring knowledge beforehand. Words: 0 semaph.sync (16%) Consider the C-program balance.c : 1 #include <pthread.h> 2 #include <stdint.h> 3 #include <stdio.h> 4 #include <stdlib.h> 5 #define MAX 10000000 // 10.000.000 6 7 int g_balance = MAX; 8 9 10 11 12 13 void *updateBalance(void *arg) { long id = (long) arg; if(id==1){ for (int i=0; i<MAX; g_balance--; i++) { 20 21 } 22 pthread_exit(NULL); 23 } 24 25 int main(void) { 26 pthread_t t1,t2; 27 int status; 28 status = pthread_create(&t1, NULL, updateBalance, (void *) 1); 29 if (status != 0) { exit(EXIT_FAILURE); } 30 status = pthread_create(&t2, NULL, updateBalance, (void *) 2); 31 if (status != 0) { exit(EXIT_FAILURE); } 32 pthread_join(t1, NULL); 33 printf("Balance is %d after thread 1. ",g_balance); 34 pthread_join(t2, NULL); 35 printf("Balance is %d after thread 2. ",g_balance); 36 return 0; 37 } When executed, it outputs something like this: $ ./balance Balance is 11453068 after thread 1. Balance is 23012458 after thread 2. 1. (4%) What should be the output value of g_balance after thread 2 if nothing goes wrong? 2. (4%) What exactly is the problem with this code? 3. (4%) How can you fix the problem in such a way that the output is guaranteed to be correct with maximum parallelism (but it might be slow)? 4. (4%) How can you fix the program in such a way that the output is guaranteed to be correct and runs fast (where maybe you ignore parallelism)? (3%) What should be the output value of g_balance after thread 2 if nothing goes wrong? 20000000 (4%) What exactly is the problem with this code? Race condition with the two threads accessing the shared variable g_balance. The threads modify the variable in three steps: read, modify, write; and can be interrupted between these steps. (4%) How can you fix the problem in such a way that the output is guaranteed to be correct with maximum parallelism (but it might be slow)? Use a mutex lock or a binary semaphore around lines 13 (g_balance--) and 17 (g_balance + 2), this allows for max parallelism but is very slow due to all the locking. (4%) How can you fix the program in such a way that the output is guaranteed to be correct and runs fast (where maybe you ignore parallelism)? Either move the locks outside the for-loops and make each thread run to completion before the other gets the lock, or move the pthread_join statements in main to make the threads run in sequence instead of parallel. correct code for question three would be something like this (but they only need to explain in their answers, they dont need to provide exact code): 1 #include <pthread.h> 2 #include <stdint.h> 3 #include <stdio.h> 4 #include <stdlib.h> 5 #define MAX 10000000 // 10.000.000 6 7 int g_balance = MAX; 8 pthread_mutex_t mutex; 9 10 void *updateBalance(void *arg) { 11 long id = (long) arg; 12 13 14 15 16 17 } if (id == 1) { for (int i=0; i<MAX; i++) { pthread_mutex_lock(&mutex); g_balance--; pthread_mutex_unlock(&mutex); 18 19 20 21 22 23 } 24 } else { 25 printf("%ld is not a valid ID. ", id); 26 } 27 pthread_exit(NULL); 28 } 29 30 int main(void) { 31 pthread_t t1,t2; 32 int status; 33 pthread_mutex_init(&mutex,0); 34 status = pthread_create(&t1, NULL, updateBalance, (void *) 1); 35 if (status != 0) { exit(EXIT_FAILURE); } 36 status = pthread_create(&t2, NULL, updateBalance, (void *) 2); 37 if (status != 0) { exit(EXIT_FAILURE); } 38 pthread_join(t1, NULL); 39 printf("Balance is %d after thread 1. ",g_balance); 40 pthread_join(t2, NULL); 41 printf("Balance is %d after thread 2. ",g_balance); 42 return 0; 43 } virt.container (6%) What is a container? How is a container different from a virtual machine? EXAM 2022 EXAM 2022 18. addrspace.paging 19. syscalls.fork 20. semaph.sync 22. fscore.fragmentation 24. io.ssd 25. virt.container 26. ossec.design EXAM 2021 EXAM 2021 15. introproc.layers 16. introproc.states 18. scheduling.mlfq 19. fscore.delete 20. syscalls.fork 21. addrspace.paging 22. threads.sync 23. fscore.filesize 25. virt.sec EXAM 2023 EXAM 2023 17 introproc.states 19 addrspace.pagetable 20 fscore.dir 21 introproc.linux 22 fscore.linux 23. syscalls.fork 24. semaph.sync 25. syscalls.theory 28 memman.theory 29 ossec.setuid