←
Back to COMP1521 Overview
返回 COMP1521 总览
COMP1521 Week 9 Quiz
Unix Files, Streams & Storage Systems
文件描述符、系统调用、元数据、链接与目录操作
Question 1
Which system call is used to open a file in Unix and returns a file descriptor?
A) read()
B) write()
C) open()
D) close()
Question 2
What is the purpose of the file descriptor 0 in Unix systems?
A) Standard output (stdout)
B) Standard input (stdin)
C) Standard error (stderr)
D) First opened file
Question 3
Which system call is used to change the current read/write position in a file?
A) fflush()
B) fseek()
C) lseek()
D) rewind()
Question 4
What is the difference between a hard link and a symbolic link?
A) Hard links work across filesystems, symbolic links don't
B) Symbolic links point to inode numbers, hard links point to filenames
C) Hard links point to the same inode, symbolic links point to a pathname
D) There is no difference in functionality
Question 5
Which system call is used to create a new directory?
A) create()
B) mkdir()
C) mknode()
D) opendir()
Question 6
What does the `stat` system call return about a file?
A) Only the file size
B) File contents
C) File metadata (inode information)
D) File descriptor
Question 7
Which of the following is NOT a standard file descriptor automatically opened by Unix?
A) 0 (stdin)
B) 1 (stdout)
C) 2 (stderr)
D) 3 (first user file)
Question 8
What is the purpose of the `O_APPEND` flag when opening a file?
A) Create the file if it doesn't exist
B) Truncate the file to zero length
C) Always write to the end of the file
D) Open in read-only mode
Question 9
Which system call is used to read directory entries?
A) read()
B) readdir()
C) scandir()
D) getdents()
Question 10
What happens when you delete a file that has multiple hard links?
A) The file is immediately deleted from disk
B) The link count is decremented, file space is freed when count reaches 0
C) All hard links become invalid
D) The file system becomes corrupted
Question 11
Which flag would you use with `open()` to ensure exclusive creation of a file?
A) O_CREAT
B) O_EXCL
C) O_TRUNC
D) O_WRONLY
Question 12
What is the purpose of the `umask` value in Unix file creation?
A) Sets the maximum file size
B) Masks out permission bits from newly created files
C) Determines file ownership
D) Sets the default file type
Question 13
Which system call would you use to duplicate a file descriptor?
A) fork()
B) dup()
C) clone()
D) copy()
Question 14
What is the difference between `read()` and `pread()`?
A) `pread()` can read from multiple files simultaneously
B) `pread()` reads from a specified offset without changing file position
C) `pread()` is always faster than `read()`
D) There is no difference
Question 15
Which of the following best describes what an inode contains?
A) File name and directory path
B) File metadata and data block pointers
C) File contents only
D) Directory structure information
Question 16
What is the purpose of the `fsync()` system call?
A) Synchronize file access between multiple processes
B) Force writes of file data and metadata to disk
C) Flush the file system cache
D) Check file system integrity
Question 17
Which system call is used to change file permissions?
A) chmod()
B) chown()
C) chgrp()
D) access()
Question 18
What does the `fcntl()` system call primarily do?
A) Create new files
B) Perform file control operations (e.g., duplicating descriptors, setting flags)
C) Read file contents
D) Write file contents
Question 19
Which of the following is true about FIFO (named pipe) files?
A) They persist after the creating process terminates
B) They can only be used by related processes
C) They work like regular files for random access
D) They require special kernel modules
Question 20
What is the typical return value of `write()` when it successfully writes all requested bytes?
A) 0
B) -1
C) The number of bytes written
D) The file descriptor
Question 21
Which system call is used to remove a directory?
A) delete()
B) rmdir()
C) remove()
D) unlink()
Question 22
What is the purpose of the `O_NONBLOCK` flag?
A) Prevents the file from being blocked by other processes
B) Makes I/O operations non-blocking (return immediately if no data available)
B) Locks the file for exclusive access
D) Enables buffered I/O
Question 23
Which system call would you use to get the current working directory?
A) getpath()
B) getcwd()
C) pwd()
D) getdir()
Question 24
What happens when you call `close()` on a file descriptor?
A) The file is deleted from disk
B) The file descriptor is deallocated and can be reused
C) All data is immediately written to disk
D) The file system is synchronized
Question 25
Which of the following best describes what a symbolic link contains?
A) File data directly
B) An inode number
C) A path name string
D) File metadata
Question 26
What is the purpose of the `access()` system call?
A) Open a file with specific permissions
B) Check real user's permissions for a file
C) Change file permissions
D) List directory contents
Question 27
Which system call is used to create a hard link?
A) link()
B) symlink()
C) ln()
D) create()
Question 28
What is the purpose of the `dirent` structure?
A) Store file metadata
B) Represent directory entries (filename and inode number)
C) Handle file permissions
D) Manage file descriptors
Question 29
Which of the following is NOT typically stored in a file's inode?
A) File size
B) File name
C) Modification time
D) Owner user ID
Question 30
What is the primary purpose of the `select()` system call?
A) Select files for backup
B) Monitor multiple file descriptors for I/O readiness
C) Choose between different system calls
D) Select a file by name
Question 31
Which system call would you use to truncate a file to a specific length?
A) truncate()
B) ftruncate()
C) Both A and B
D) resize()
Question 32
What is the difference between `O_RDONLY` and `O_WRONLY` flags?
A) O_RDONLY creates the file, O_WRONLY doesn't
B) O_RDONLY opens for reading only, O_WRONLY for writing only
C) O_RDONLY is for text files, O_WRONLY for binary files
D) No difference
Question 33
Which system call is used to change the ownership of a file?
A) chown()
B) chmod()
C) chgrp()
D) owner()
Question 34
What is the purpose of the `DIR` structure in directory operations?
A) Store directory permissions
B) Represent an open directory stream
C) Contain directory metadata
D) Handle file locking
Question 35
Which of the following best describes what happens when you reach EOF during a `read()` operation?
A) Returns -1 and sets errno to EOF
B) Returns 0
C) Blocks until more data is available
D) Returns the file descriptor
Question 36
What is the purpose of the `pathconf()` and `fpathconf()` functions?
A) Configure file paths
B) Get configurable pathname limits
C) Compare two file paths
D) Validate file path syntax
Question 37
Which system call is used to create a new named pipe (FIFO)?
A) pipe()
B) mkfifo()
C) mknod()
D) Both B and C
Question 38
What is the purpose of the `mmap()` system call in the context of file I/O?
A) Map a file into memory for direct access
B) Copy file contents to a new location
C) Move files between directories
D) Compress file data
Question 39
Which of the following is true about the `writev()` system call?
A) Writes to multiple files simultaneously
B) Writes data from multiple buffers in a single call
C) Writes data in a specific vector format
D) Writes data with verification
Question 40
What is the primary difference between `lstat()` and `stat()`?
A) `lstat()` is faster than `stat()`
B) `lstat()` returns information about the link itself, not the file it points to
C) `lstat()` works only on local files, `stat()` works on remote files
D) No difference
Submit Quiz