calls
What does the fork() system call do?
It creates a new process by duplicating the current process.
What system call is used to open a file?
open()
What system call configures a device like a terminal?
ioctl()
Explain the difference between fork() and exec()?
fork() creates a new process, exec() replaces the current process image with a new one.
Describe what happens when read() is called on a file descriptor?
Data is read from the file into a buffer in memory.
Explain how read() differs when used on a device vs a regular file.
On devices, read() gets real-time input (e.g., from keyboard), unlike static file data.
Write a small scenario where wait() is used in a parent process?
A parent process creates a child using fork() and then uses wait() to pause until the child finishes
How would you write “Hello” into a file named test.txt using system calls?
Use open() with write flag, then write() to write the text, and close() afterward.
How would you read from a USB device in Linux?
Use open() to access the device file (e.g., /dev/sda), then read().
What happens if a process calls fork() multiple times in a loop?
Multiple child processes are created, possibly exponentially depending on structure.
Analyze the impact of not closing a file after using it?
It can lead to memory leaks, file descriptor exhaustion, or data not being written properly.
Analyze the advantages and disadvantages of using ioctl() for device control.Pros:
pros: flexible, powerful;
Cons: device-specific, harder to standardize.
Design a process management routine using fork(), exec(), and wait() to load a new program.
Use fork() to create a child, exec() to load the new program, and wait() in the parent to wait for child termination.
Write a pseudo-code to read the first 100 bytes of a file and print it.
Use open() → read() → write() to STDOUT → close()
Design a system to control fan speed using a device file and ioctl().
Identify the device file → Use open() → Set speed with ioctl() → close()