Unix Multiple Choice Questions on “File handling System Calls”.
1. Which library function is used for printing error messages?
a) strerror
b) stderror
c) strer
d) ptrerror
Answer: a
Clarification: 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.
a) True
b) False
Answer: b
Clarification: 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
Answer: b
Clarification: 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?
a) EPERM
b) ENDENT
c) EIO
d) EEXIST
Answer: b
Clarification: 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?
a) EPERM
b) ENDENT
c) EIOR
d) EEXIST
Answer: c
Clarification: 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?
a) 3
b) 2
c) 5
d) 1
Answer: a
Clarification: 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.
a) True
b) False
Answer: a
Clarification: 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
Answer: d
Clarification: 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
c) vtable
d) vttable
Answer: a
Clarification: 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?
a) chdir
b) fchdir
c) mkdir
d) chdir and fchdir
Answer: d
Clarification: 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.
a) True
b) False
Answer: a
Clarification: 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?
a) mkdir
b) rmdir
c) chdir
d) mkdir and rmdir
Answer: d
Clarification: 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.
a) mknod
b) mkdr
c) rmdir
d) chdir
Answer: a
Clarification: 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
Answer: b
Clarification: 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.
a) link
b) symlink
c) unlink
d) delink
Answer: c
Clarification: The unlink system call removes the directory entry for the file (the argument) and decrements the link count in its inode by one.
