8.Write a program that creates two children, and connects the standard output of one to the standard input of the other, using the pipe() system call.
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/wait.h> int main(int argc, char *argv[]) { int rc; int fd[2], i; pipe(fd); for(i = 0; i < 2; i++) { rc = fork(); if(rc <= 0) break; } if(rc < 0) exit(1); else if(i == 0) { close(fd[1]); char buf[1024]; read(fd[0], buf, 1024); printf("%s\n", buf); } else if(i == 1) { close(fd[0]); char buf[1024]; scanf("%s", buf); write(fd[1], buf, strlen(buf) + 1); } else { for(int j = 0; j < 2; j++) wait(NULL); } return 0; }注意:该行代码的执行结果与上图有出入,因为上图假设长工作已经运行了一段时间了,而执行该代码时长工作首先被放入queue 2中。
How would you configure the scheduler parameters to behave just like a round-robin scheduler? 只使用一个队列即可。因为这样一来所有的工作的优先级都相同,按照规则3进行轮转。Craft a workload with two jobs and scheduler parameters so that one job takes advantage of the older Rules 4a and 4b (turned on with the -S flag) to game the scheduler and obtain 99% of the CPU over a particular time interval. ./mlfq.py -q 100 -l 0,100,99:0,100,0 -i 0 -S -c Given a systemwith a quantum length of 10 ms in its highest queue, howoften would you have to boost jobs back to the highest priority level (with the -B flag) in order to guarantee that a single long-running (and potentiallystarving) job gets at least 5% of the CPU? 最坏的情况是,该长工作只有被放在最高优先级队列中时,才有被调度的机会。 在1000ms的CPU时间中,至少需要每200ms提升一次优先级。One question that arises in scheduling is which end of a queue to add a job that just finished I/O; the -I flag changes this behavior for this scheduling simulator. Play around with some workloads and see if you can see the effect of this flag. 执行完调度的进程应该插入到队列的首端还是末端?比较一下。(略)