卷別
計算機結構與作業系統(B)
選擇國立臺灣大學 2022 · 考試 · 第 3 題
(5 pts) The following line opens a file for write only.
int fd = open(file_name, O_CREAT | O_EXCL | O_WRONLY, new_file_mode);
if (fd == -1) {
/* Handle Error */
}
...
Please indicate the sequence of executing the above line if fd is equal to -1, using the symbol in the circle.
The figure ("Opening a file") shows the standard schematic view of the open() system call flow across user space (the open(filename) call), kernel memory (the system-wide open-file table and the per-process open-file table), and secondary storage (the directory structure and the File Control Block). Labelled circles mark specific points along the flow; a full successful open traverses circles A → B → C → D (user-space call → directory lookup → system-wide open-file table entry → per-process open-file table entry, returning a valid fd), while circle E marks the short-circuit error-return path taken when the file cannot be opened (fd == -1), bypassing the open-file-table steps entirely.
- (A)A -> B -> C -> D
- (B)E -> B
- (C)A -> D
- (D)A -> E
- (E)B -> C -> A