b05902xxx 板


LINE

※ [本文转录自 NTU-Exam 看板 #1KX-CA3O ] 作者: yangchris11 (歪彦) 看板: NTU-Exam 标题: [试题] 103-1 郑卜壬 系统程式设计 期中考 时间: Wed Dec 10 14:07:04 2014 课程名称︰系统程式设计 课程性质︰大二必修 课程教师︰郑卜壬 开课学院:电资学院 开课系所︰资讯工程学系 考试日期(年月日)︰2014/11/19 考试时限(分钟):180min 试题 : Systems Programming (Fall,2014) Mid-Term Exam November 19, 2014 ========================================================================== 1. Answer the following questions. (20pts) (a) Where are the following data structures located? User space or kernel space. (4pts) Process control block: Open file descriptor table: File object (i.e.,FILE): V-node (or i-node) table: (b) Compare the difference (including definition and advantages) between advisory locking and mandatory locking. (4pts) Advisory: Mandatory: (c) Explain how file I/O benefits from using standard I/O library's buffer and kernel's buffer cache, respectively. Determine if they can save much in user CPU, system CPU, and clock (or response) time. (4pts) Standard I/O lib: Buffere cache: (d) Define buiult-in and external shell commands, respectively. Why should some commands be built-in or exyernal commands? Built-in: External: (e) The amount of disk space used by a file is integer multiples of disk block size. Explain (A) why the length of a file might be greater than its disk space and (B) why the disk space actually occupied by a file might be geater than its file length. (4pts) (A): (B): 2. Alice wants to write a server allowing people to upload their files via network connection simultaneously. Each connection from a client sends a request to upload a file to the server. Once the connection from a client is accepted by the server, Alice plans to design a loop, which iteratively * reads the data sent by the client via a new connected socket descriptor sock_fd, * writes the client's data to a file, and * synchronize standard C library's buffer or kernel's buffer cache if necessary, assuming that the file descriptor(or file stream) has been set up already. She's got several choices when developing such a program as follows: * I/O models for networking: blocking I/O, non-blocking I/O, multiplexing I/O * File I/O: buffered I/O, unbuffered I/O Buffered I/O: different buffer sizes Unbuffered I/O: character-at-a-time I/O, line-at-a-time I/O * Buffer/disk synchronization: fflush(), fsync() Please help Alice to make decisions. (a) Please specify multiplexing I/O and its advantages. (4pts) (b) Consider I/O models for networking. Which model saves the most in user CPU time? Which model wastes the most in user CPU time? Which model needs longer time to copy the data from the kernel to the process? Explain your answers. (6pts) (c) Please complete the following table for performance comparison between various settings. Assume blocking I/O is adopted as the network I/O model, the file to be uploaded is very large, and the problems of network traffic and system load are ignored here. The file system has 4K-byte blocks. The standard I/O library chooses the optimal size, i.e., 4K bytes, for buffering. In this table, the first line stands for the baseline, which considers the combination of unbuffered I/O, 4K buffer size, and no disk synchronization. A, B, and C are time in seconds. Please fill in the table with >X, <X, or X, where X is A, B, or C. Theymean the time required is much larger than, less than, and close to X, respectively. (13pts) graph : http://ppt.cc/Wi9b 3. Alice plans to develop an encryption program encrypt to encode an input file. The executable file is invoked as follow: $ ./encrypt <plaintext> -o <ciphertext> where <plaintext> is the input file to be encrypted ; <ciphertext> is the encrypted output file. To know what plain texts have been encrypted, the encrypt program logs statistics in the file /alice/logfile. The owner of the directory /alice is Alice; the file /alice/logfile is writable only by Alice. Alice sets the setuid bit on encrypt, ensuring that encrypt run by someone else can update /alice/logfile. (17pts) (a) If only Alice can insert and delete files in /alice, what minimum access rights (i.e.,read, write, and execute) should be used for the directory /alice? Only consider the owner class here. Your answer should be in the form of “rwx”, “r-x”, or the like. (2pts) Owner: (b) If Bob runs the following command successfully: $./encrypt /bob/plaintext -o ciphertext what minimum access rights should be used for the directory /bob? Only consider the other class here. (2pts) Other: (c) There is a security hole in the file encrypt. It's possible for Bob to update Alice's file /alice/testfile, which is writable only by Alice. Why? (3pts) (d) Alice tries to fix the problem mentioned in (c) by checking whether the "real" user can write <ciphertext> before opening it. Here is an excerpt from her code: int fd; if (access("ciphertext", W_OK) < 0) exit(-1); fd = open("ciphertext", O_WRONLY|O_TRUNC); Suppose the file ciphertext is owned and writable only by Bob. It is still possible for Bob to write Alice’s file /alice/testfile, which is writable only by Alice. Why? (4pts) (e) Please help Alice rewrite the excerpt so that access() and open() can be performed atomically. That is, either both of them are performed, or none are performed. Insert your code in Sections A and B. You could declare your own variables in Section A or create your own files if needed. Explain why your code works. (6pts) int fd; // Section A if (access("ciphertext", W_OK) < 0) exit(-1); fd = open("ciphertext", O_WRONLY|O_TRUNC); // Section B 4. Alice plans to write a program score to score students' programs. When issuing the following command, she wants score to call fork() to create three child processes. Each child process calls exec() to execute one program, i.e., prog-i (i=1..3). $ ./score prog-1 prog-2 prog-3 Each child process is asked to first read data from its standard input and then write the result to its standard output. The output will then be sent to score through a pipe. The parent process first writes data to each pipe and then reads the result from the pipe. Alice takes the left model into account, where pfdj (j=1..3) is the file descriptor used by pipe(). The model has three pipelines. It should allow the child processes to send data simultaneously and don't generate any zombie processes. The score program, i.e., score.c, is notcomplete. (28pts) int main( int argc, char *argv[] ) // score.c { int i, pid; // Section A for (i=1; i<argc, i++) { // Section B pid = fork(); if ( pid == 0 ) { // Section C execlp( argv[i], argv[i], (char *) 0 ); } // Section D } // Section E } (a) Fill the following form with the system calls pipe(), dup2(), close(), and wait() to build up the model. Unused file descriptors should be closed. You could declare your own variables in Section A. Sections A~E are the places where you could put your code in score.c. Error handling and data transferring (e.g., read() and write()) can be ignored. (10pts) (b) Deadlock may occur if both of the parent and the clients call fgets() and fputs() to access data via pipe. Please (1) define deadlock, and (2) explain why buffered I/O may lead to a deadlock. (6pts) (1): (2): (c) Deadlock may occur if Alice makes some changes in score.c, including changing fork() into vfork(), changing execlp() into _exit(0), calling read() followed by write() in Section C, and calling write() followed by read() in Section E. read() and write() are used to access data via pipe. Please (1) explain why such changes may lead to a deadlock, and (2) how does the copy-on-write technique speed up the execution of fork()? (6pts) (1): (2): (d) Alice serves as a TA for SP class. She wants each student to run score for submitting his/her program. In this case, only one child process is allowed. The program score not only checks if the output of the student' program prog-1 is correct but also writes the student's score into the file scorefile. Note that the owners of score and scorefile are Alice. The access permission of score is 04755 (octal value); the access permission of scorefile is 00600 (octalvalue). (1) There is a security hole. What is it? (2) Discuss if the problem can be fixed by running prog-1 as the parent and score as the child. The parent reads and then writes data through pipe; the child writes and then reads data through pipe. Explain your answer. (6pts) 5. Please answer the following file-system-related questions. (12pts) (a) How many i-nodes and data blocks will be visited when the file, /home/user/Alice/SP/assignment.c, is opened? Assume all directories and files are one block long. /home/user is a symbolic link pointing to /user; the others are all hard links. Briefly explain your answer. (4pts) (b) Why does any directory always have at least a (hard) link count of 2 ? (2pts) (c) When traversing a directory tree, we often need to know if a file has been visited to avoid a loop. However, each file may have multiple aliases in UNIX. Please give an effective way to detect if a file has been visited or not. (2pts) (d) Under what conditions are a file's contents really removed from a disk? (4pts) --



※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 140.112.25.106
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/NTU-Exam/M.1418191626.A.0D8.html
1F:推 rod24574575 : 已收资讯系! 12/10 14:56
2F:推 miku1112 : 勇者 给推 12/10 15:34
3F:嘘 ryuchenchang: 老师都收考卷了你还贴。低调 12/13 22:19
4F:嘘 brian980466 : 低调 04/24 10:15



※ 发信站: 批踢踢实业坊(ptt.cc)
※ 转录者: dyadi (140.112.16.135), 11/08/2017 16:40:32
5F:嘘 Kikokushijo: 害我以为今天pj考期中 11/08 16:58
6F:→ dyadi: 抓到 翘课 11/08 22:57
7F:→ dannyko: 留言笑死 我早知道也偷渡个单班考卷 11/09 01:03
8F:→ dyadi: 今天pj上课说我们可以写写看网路上的考古题 代表他知道而且 11/09 01:08
9F:→ dyadi: 不反对学生公布考题吧(?) 11/09 01:09
10F:推 yangfeng: 笑死 11/09 12:53







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:iOS站内搜寻

TOP