Unix Questions and Answers – File handling System Calls – 1

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?
a) strerror
b) stderror
c) strer
d) ptrerror
View Answer

Answer: a
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.
a) True
b) False
View Answer

Answer: b
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
View Answer

Answer: b
Explanation: The errno 13 displays the message “permission denied”. The symbolic constant for this errno is EACCES.
advertisement
advertisement

4. What is the symbolic constant for errno 2?
a) EPERM
b) ENDENT
c) EIO
d) EEXIST
View Answer

Answer: b
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?
a) EPERM
b) ENDENT
c) EIOR
d) EEXIST
View Answer

Answer: c
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?
a) 3
b) 2
c) 5
d) 1
View Answer

Answer: a
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.
a) True
b) False
View Answer

Answer: a
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.
advertisement

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
View Answer

Answer: d
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
c) vtable
d) vttable
View Answer

Answer: a
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.
advertisement

10. Which of the following system calls performs the action of cd command?
a) chdir
b) fchdir
c) mkdir
d) chdir and fchdir
View Answer

Answer: d
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.
a) True
b) False
View Answer

Answer: a
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?
a) mkdir
b) rmdir
c) chdir
d) mkdir and rmdir
View Answer

Answer: d
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.
a) mknod
b) mkdr
c) rmdir
d) chdir
View Answer

Answer: a
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
View Answer

Answer: b
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.
a) link
b) symlink
c) unlink
d) delink
View Answer

Answer: c
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.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.