logo

Crowdly

2025W Operating Systems (CS-3520-01)

Шукаєте відповіді та рішення тестів для 2025W Operating Systems (CS-3520-01)? Перегляньте нашу велику колекцію перевірених відповідей для 2025W Operating Systems (CS-3520-01) в moodle31.upei.ca.

Отримайте миттєвий доступ до точних відповідей та детальних пояснень для питань вашого курсу. Наша платформа, створена спільнотою, допомагає студентам досягати успіху!

The following C code was our first attempt to make a lock using a flag to indicate if the lock was acquired.

typedef struct __lock_t { int flag; } lock_t;

void init(lock_t *mutex) {

mutex->flag = 0;

}

void lock(lock_t *mutex) {

while (mutex->flag == 1) // TEST the flag

; // spin-wait (do nothing)

mutex->flag = 1; // now SET it !

}

void unlock(lock_t *mutex) {

mutex->flag = 0;

}

How will this code perform in terms of correctness and efficiency?

Переглянути це питання
Given the choice between evicting a dirty page or a clean page from physical memory, which one should you choose and why?
Переглянути це питання
A page fault occurs when:
Переглянути це питання

Which of the following tasks would have improved performance if the OS prefetches the next page along with the requested page from disk on page selections?

Переглянути це питання
When the OS decides to swap a page out of physical memory, what is the optimal choice that will result in the fewest possible page faults?
Переглянути це питання

Suppose it takes 50ns to access memory and 5000ns to access disk. To guarantee that Average Memory Access Time (AMAT) is at most 100ns, what must be true about the page-hit-rate H (the percent of pages accessed that are present in physical memory)?

Переглянути це питання
Suppose we have 4 pages (P0, P1, P2, and P3) in physical memory and need to choose one to evict using the clock algorithm to approximate LRU. Suppose further that each page has its use bit equal to 0 and the clock hand initially points to P0 and visits them in order.

Which page will be evicted?

Переглянути це питання
Which of the following is true of the address space of a multithreaded process?
Переглянути це питання

Recall the code below from class where we used a condition variable to make sure the child runs before the parent prints. Why did we include the int variable done if signalling and waiting is done automatically with condition variables?

int done = 0;

pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;

pthread_cond_t c = PTHREAD_COND_INITIALIZER;

void thr_exit() {

Pthread_mutex_lock(&m);

done = 1;

Pthread_cond_signal(&c);

Pthread_mutex_unlock(&m);

}

void *child(void *arg) {

printf("child");

thr_exit();

return NULL;

}

void thr_join() {

Pthread_mutex_lock(&m);

while (done == 0)

Pthread_cond_wait(&c, &m);

Pthread_mutex_unlock(&m);

}

int main(int argc, char *argv[]) {

printf("parent: begin");

pthread_t p;

Pthread_create(&p, NULL, child, NULL);

thr_join();

printf("parent: end");

return 0;

}

Переглянути це питання

When using a semaphore to ensure the child thread runs before the parent executes further as in the code snippet below, what value should the semaphore be initialized too (i.e., what should X be)?

sem_t s;

void *child(void *arg) {

printf("child");

sem_post(&s); // signal here: child is done

return NULL;

}

int main(int argc, char *argv[]) {

sem_init(&s, 0, X); // what should X be?

printf("parent: begin");

pthread_t c;

pthread_create(c, NULL, child, NULL);

sem_wait(&s); // wait here for child

printf("parent: end");

return 0;

}

Переглянути це питання

Хочете миттєвий доступ до всіх перевірених відповідей на moodle31.upei.ca?

Отримайте необмежений доступ до відповідей на екзаменаційні питання - встановіть розширення Crowdly зараз!