This set of Unix Multiple Choice Questions & Answers (MCQs) focuses on “File handling System Calls – 1”.
1. Which library function is used for printing error messages?
Explanation: The library function strerror, uses the error number as argument and returns a pointer to the string representing the error.
2. perror also uses error number to print the error messages.
Explanation: There is another library function, perror which is used for printing the error messages. But perror doesn’t use the errno (error number) as an argument.
3. What is the significance of errno 13?
a) not a super user
b) no such file and directory
c) permission denied
d) no space left on device
Explanation: The errno 13 displays the message “permission denied”. The symbolic constant for this errno is EACCES.
4. What is the symbolic constant for errno 2?
Explanation: The symbolic constant for errno 2 is ENDENT. It displays the message “no such file and directory”.
5. Which of the following is not a valid symbolic constant?
Explanation: EPERM displays not a super user (errno 1), ENDENT displays no such file or directory (errno 2), EEXIST displays file exist (errno 17).
6. How many data structures does the kernel maintain in memory that contain information about an open file?
Explanation: The kernel maintains three data structures in memory that contain all information about an open file that a process needs to access. These data structures are:
The file descriptor table
The file table
The vnode table
7. The file descriptor table contains all file descriptors for a process.
Explanation: The file descriptor table contains all allocated file descriptors for a process. Each entry points to the file table. The file descriptor is stored along with a flag in this table.
8. The file table contains _________
a) mode of opening
b) status flags
c) offset pointer, reference count
d) mode of opening, status flags, offset printer and reference count
Explanation: Every entry in the file descriptor table points to a file table. This table contains all the data which is relevant to an opened file.
9. The vnode table is also called _____
a) inode table
b) file table
Explanation: The file table contains a pointer to the vnode table, which is the third table in the scheme. It is also called as inode table. This table contains all the information present in the inode except that this structure is maintained in memory.
10. Which of the following system calls performs the action of cd command?
d) chdir and fchdir
Explanation: There are two system calls that perform the action of cd command. They are chdir and fchdir which uses pathname and a file descriptor respectively as an argument.
11. Directories can also be opened, read and written in the same way as regular files.
Explanation: Directories are also files, and they can also be written, read and opened in the same way as regular files. We can use open, close and read system calls for performing these tasks.
12. For creating and removing directories, which of the following system calls are used?
d) mkdir and rmdir
Explanation: A non privileged user uses mkdir and rmdir calls for creating and removing directories respectively.
13. A super user can use ___ call for creating a directory.
Explanation: A superuser can use the mknod system call to create a directory but a non privileged user has to use the mkdir call.
14. For creating a hard and symbolic link, which system calls are used?
a) link, unlink
b) link, symlink
c) unlink, ulink
d) hlink, slink
Explanation: Unlike the ln command which creates both hard and symbolic links, the system call library has two separate functions, link and symlink for these tasks.
15. For removing a link, ____ is used.
Explanation: The unlink system call removes the directory entry for the file (the argument) and decrements the link count in its inode by one.
Sanfoundry Global Education & Learning Series – Unix.
To practice all areas of Unix, here is complete set of 1000+ Multiple Choice Questions and Answers.