Lab4: Questions

Q1. Consider the following POSIX signal example code. Can you elaborate how to design the kernel to support it?

In question 1you should explain the signal mechanism in 3 parts, signal registration
signal generation, and signal delivery

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <stdio.h>
#include <signal.h>
#include <unistd.h>

void handler(int sig) {
printf("Hello\n");
}

int main()
{
signal(SIGINT, handler);
char buf[256];
int n = read(0, buf, 256);
buf[n] = '\0';
printf("Bye %s\n", buf);
}

signal registration: 註冊特定 signal 的 signal handler, i.e. signal(SIGINT, handler)

signal generation: 對特定 process 發起 SIGINT signal,OS 會紀錄在 task_struct 但還沒執行,稱為 pending signal

signal delivery: 等到該 process 執行,且 signal 沒有被 blocked ,執行該 signal 對應handler

Ref: https://hackmd.io/@minyeon/B1a11SNAD

Q2. Can you prevent all possible context switch by disabling interrupt?

不可,kernel task 可以藉由呼叫 schedule 主動 context switch

Q3. Do you think microkernel need to be preemptive kernel or not? Why or why not?