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/m.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燈, 水草

請輸入看板名稱,例如:BuyTogether站內搜尋

TOP