This set of Unix Multiple Choice Questions & Answers (MCQs) focuses on “System Calls Basics – 2”.
1. Which of the following system call is used for closing a file?
a) open
b) lseek
c) close
d) write
View Answer
Explanation: A program automatically closes all open files before termination, but it’s a good practice to close them explicitly. The close system call is used for closing a file.
int close (int fd)
2. close system call returns ____
a) 0
b) -1
c) 1
d) 0 and -1
View Answer
Explanation: The return type of close system call is an integer. It either returns 0 if the file is closed successfully or -1 otherwise.
3. ____ system call is used for writing to a file.
a) read
b) write
c) close
d) seek
View Answer
Explanation: write system call is required for writing to a file which has previously been opened with the open system call. write system call returns the number of characters written.
4. write system call returns -1 when ___________
a) if disk fills up while write is in progress
b) when file doesn’t exist
c) if the file size exceeds the system’s limit
d) if disk fills up while write is in progress and if the file size exceeds
View Answer
Explanation: write system call returns the number of characters written. However, it will return -1 if if disk fills up while write is in progress or if the file size exceeds the system’s limit.
5. ____ system call is used for positioning the offset pointer.
a) read
b) write
c) open
d) lseek
View Answer
Explanation: The lseek system call moves the file offset pointer to a specified point. It doesn’t do any physical I/O rather it determines the position in the file where the next I/O operation will take place.
6. Which of the following offset is used with lseek system call to set the offset pointer to the end of the file?
a) SEEK_SET
b) SEEK_END
c) SEEK_CUR
d) SEEK_CR
View Answer
Explanation: The offset signifies the position of the offset pointer which can take one of these three values:
SEEK_SET - offset pointer set to the beginning of file SEEK_END - offset pointer set to the end of file SEEK_CUR - offset pointer remains at current location
7. Which of the following system call is used for truncating a file?
a) truncate
b) ftruncate
c) trunk
d) truncate and ftruncate
View Answer
Explanation: The truncate and ftruncate calls can truncate a file to any length. These calls are often used in combination with lseek to overwrite a certain segment of a file.
8. truncate needs the ___ of the file as an argument but ftruncate works with _______
a) pathname, file descriptor
b) file descriptor, pathname
c) pathname, pathname
d) file descriptor, file descriptor
View Answer
Explanation: The truncate and ftruncate calls can truncate a file to any length. truncate needs the pathname of the file as an argument but ftruncate works with the file descriptor.
Sanfoundry Global Education & Learning Series – Unix.
To practice Unix, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Apply for Computer Science Internship
- Check Computer Science Books
- Check Unix Books
- Practice Computer Science MCQs
- Practice MCA MCQs