Unit3 - Subjective Questions

CSE325 • Practice Questions with Detailed Answers

1

Explain the concept of a File Descriptor in the context of Operating Systems. Which standard file descriptors are automatically opened for a process?

2

Describe the syntax of the open() system call. Explain the purpose of the essential flags: O_RDONLY, O_WRONLY, O_RDWR, and O_CREAT.

3

Analyze the return values of the read() system call. What does a return value of 0, -1, and a positive integer signify?

4

Write a C program using system calls (open, read, write) to copy the contents of source.txt to destination.txt.

5

Explain the lseek() system call in detail. Specifically, describe the three options for the whence argument: SEEK_SET, SEEK_CUR, and SEEK_END.

6

Differentiate between System Calls (e.g., open, read) and Library Functions (e.g., fopen, fread) regarding file handling.

7

Why is the close() system call important? What are the consequences of failing to close file descriptors in a long-running process?

8

Describe how to determine the size of a file using the lseek() system call. Provide a code snippet.

9

Explain the concept of File Holes (Sparse Files) and how they can be created using lseek() and write().

10

Discuss the significance of the mode argument in the open() system call. When is it mandatory?

11

Write a C program that takes a filename as a command-line argument and prints the last 10 bytes of that file to the standard output.

12

What is the purpose of the O_APPEND flag in the open() system call? How does it ensure atomic writes?

13

Explain the parameters of the write() system call. What happens if the return value is less than the number of bytes requested?

14

How does the O_TRUNC flag affect an existing file when used with open()?

15

In a C program, how can you read input from the keyboard without using scanf or gets? Provide a small example.

16

What header files are strictly required to use open, read, write, close, and exit in a C program on a UNIX-like system?

17

Derive the logic to check if a file exists using the open() system call without modifying the file.

18

Describe the relationship between the User File Descriptor Table and the System-wide File Table.

19

What is the specific behavior of lseek() when used on a file descriptor associated with a Pipe, FIFO, or Socket? Explain why.

20

Write a C program snippet that redirects STDOUT to a file named log.txt using open, close, and dup (or dup2).