Unit 3 - Practice Quiz
CSE325
1
Which header file is primarily required to use the open() system call and its flags like O_RDONLY?
2
Which header file defines the read(), write(), and close() system calls?
3
What is the return type of the open() system call?
4
If the open() system call fails, what value does it return?
5 Which integer value typically represents the Standard Input (stdin) file descriptor?
6
Which flag is used with open() to open a file for writing only?
7
Consider the following code snippet:
int fd = open("file.txt", O_CREAT | O_WRONLY, 0644);
What is the purpose of the third argument (0644)?
8
Which bitwise operator is used to combine multiple flags in the open() system call?
9
What does the read(fd, buf, count) system call return on success?
10
What is the return value of read() when the end of the file (EOF) is reached?
11
What is the primary difference between write() and the standard library function fwrite()?
write is a system call, fwrite is a library function.
write is buffered, fwrite is unbuffered.
write uses FILE*, fwrite uses file descriptors.
12
Which flag ensures that every write() operation appends data to the end of the file, regardless of the current file offset?
13
What does the close(fd) system call return upon successful completion?
14
What happens if you attempt to write() to a file descriptor that was opened with O_RDONLY?
15
Which lseek directive is used to set the file offset relative to the beginning of the file?
16
Consider: off_t new_pos = lseek(fd, 0, SEEK_CUR);
What does new_pos contain after this call?
17
Which code snippet correctly calculates the size of a file using lseek?
lseek(fd, 0, SEEK_SET)
lseek(fd, 0, SEEK_END)
lseek(fd, 1, SEEK_END)
lseek(fd, 0, SEEK_CUR)
18
What is the data type of the file offset returned by lseek?
19
What does the O_TRUNC flag do when used with open()?
20
If open() is called with O_CREAT but without O_EXCL, and the file already exists, what happens?
21
What happens if you use lseek() on a file descriptor associated with a pipe or socket?
22
In the call write(fd, buf, count), what does the count argument represent?
buf.
23
What is the value of the file descriptor returned by open() when successful?
24
Which type is used for the count argument (number of bytes) in read() and write()?
25
What is the result of lseek(fd, -10, SEEK_END)?
26
What is a "file hole" created by lseek?
27
Which error code is typically set if open() fails because the file does not exist (and O_CREAT was not specified)?
28
What happens to the file offset after a successful read(fd, buf, 100)?
29
The ssize_t return type of read() and write() is:
30
Which of the following is NOT a valid mode for lseek()?
31
If a process calls close(1), what effect does it have?
32
What does O_EXCL combined with O_CREAT ensure?
33 Which permission value in octal represents read/write for owner, read-only for group, and read-only for others?
34
In the statement read(fd, buf, n), who is responsible for allocating memory for buf?
read function automatically.
35
What does O_RDWR stand for?
36 Which system call is used to delete a file name from the filesystem?
37
If you perform lseek(fd, 10, SEEK_SET), where is the file pointer positioned?
38 What happens if a process forks regarding open file descriptors?
39
Why is it important to check the return value of write()?
40 What is the maximum number of files a process can open?
41
When opening a file with O_CREAT, which argument must be supplied that is otherwise optional?
42
What does the EBADF error indicate?
43
If read() is interrupted by a signal before reading any data, what does it typically return?
44 Which flag allows a file to be opened in non-blocking mode?
45
In the command cat file.txt > output.txt, the shell opens output.txt and uses dup2 to redirect which file descriptor?
46
If you open a file with O_WRONLY | O_APPEND, and two processes write to it simultaneously, what guarantees does the OS provide?
47
What is the typical prototype for the open system call?
int open(const char *pathname, int flags, ...);
void open(char *name);
FILE *open(const char *path, char *mode);
int open(int fd, int flags);
48 Which of the following refers to the specific entry in the system-wide open file table?
49
If lseek returns -1, which variable should be checked to determine the error?
50
Can read() return fewer bytes than requested (count) without it being an error?