8Q-Operating systems: Question? When a user program makes a system call to read
ID: 666664 • Letter: 8
Question
8Q-Operating systems:
Question?
When a user program makes a system call to read or write a file from disk, it provides an indication of which file it wants, a pointer to the data buffer, and the count. Control is then transferred to the operating system, which calls the appropriate driver. Suppose that the driver starts the disk and continues until an interrupt occurs. Why, when reading the disk, must the caller be blocked? Does a caller need to be blocked when writing to disk too? Why or why not?Explanation / Answer
Answer:
System calls:
Open:
syntax: int open(char *path/filename,int <flags>)
This system call is to open a file with specific flags like O_RDONLY,O_WRONLY,O_CREAT and O_APPEND
returns integer of file descriptor. It returns -1 if failed
read/write:
syn: ssize_t read(int fd, void *buffer, size_t <buffer>)
syn: ssize_t write(int fd, void *buffer, size_t <buffer>)
Both of the functions are used to read and write the data from files. It return count of bytes read or write on the file. Returns 0 if no data found.
Why, when reading the disk is blocked?
-- If file is accessed by a reader kind of process then it allows other readers to read without interruption to current reading
-- If file is reading by a reader, there might be entry of new writer, which is having higher priority or starved from long time. Then running reader is interrupted and blocked
-- If file is reading by a reader, due to round robin scheduling, turnup is reached to a writer, then running reading is interrupted and blocked
Does a caller need to be blocked when writing to disk too? Why and why not?
-- When a writer is accessing a disk file, then no other reader/writer is allowed to access the disk file. Then new caller of reader or writer is blocked
-- But some time new arrived writer/reader is having higher priority of execution, then new caller need not wait. Current running writer is interrupted and blocked
-- If any round robin sheduling time quantum is expired to current writer, then running writer is blocked
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.