Unix Questions and Answers – File Handling System Calls – 2

This set of Basic Unix Questions and Answers focuses on “File handling System Calls – 2”.

1. ____ system call is used for renaming a file, directory or symbolic link.
a) renam
b) rename
c) ren
d) change
View Answer

Answer: b
Explanation: The rename call is used for renaming any type of file. It can rename a file, a directory or a symbolic link.

2. S_IFxxx macros are used for checking the file types.
a) True
b) False
View Answer

Answer: a
Explanation: All UNIX systems provide a set of macros beginning with S_IF (often called S_IFxxx macros) that provide us with a function of checking the file type. But modern UNIX system performs this task in a more simplified manner using S_ISxxx macros.

3. Which of the following macro returns true if the file type is a directory?
a) S_ISREG
b) S_ISDIR
c) S_ISCHR
d) S_ISFIFO
View Answer

Answer: b
Explanation: The S_ISDIR macro returns true if the file type is a directory. The S_ISREG returns true if the file type is regular.
advertisement
advertisement

4. For checking a file access rights, ___ system call is used.
a) acc
b) access
c) axs
d) filert
View Answer

Answer: b
Explanation: By using the access system call, we can check the file’s access rights. It looks at the real UID and real GID of the user running the program and determines that whether the file is accessible by the real user.

5. Which of the following is used with access call for checking the owner’s permissions?
a) R_OK
b) W_OK
c) X_OK
d) R_OK, W_OK, X_OK
View Answer

Answer: d
Explanation: By using the access system call, we can check the file’s access rights. We’ve to specify one of the following four values to define the permission which is needed to be tested.

Note: Join free Sanfoundry classes at Telegram or Youtube
R_OK    -    read permission OK
W_OK    -    write permission OK
X_OK    -     execution permission OK
F_OK    -    file exists

advertisement

6. chmod and fchmod calls are used for changing file permissions.
a) True
b) False
View Answer

Answer: a
Explanation: chmod and fchmod calls are used for changing the file permissions. Chmod uses pathname for identifying a file while fchmod uses the file descriptor.

7. Both the owner and group owner can be changed by ____ call.
a) chown
b) chgrp
c) chuser
d) ch
View Answer

Answer: a
Explanation: The chown system call is used to change both the owner and group owner. It has three states; chown, fchown, lchown.
advertisement

8. For changing the time stamps, _____ system call is invoked.
a) atime
b) utime
c) mtime
d) ch
View Answer

Answer: b
Explanation: utime system call is used to change a file’s modification and access times.

9. System calls and library functions are same.
a) True
b) False
View Answer

Answer: b
Explanation: System calls are built into the kernel, but library functions are built on top of them. When a system call is invoked, the pre-processor switches to kernel mode and returns to the user mode when the call completes.

10. Which of the following system call uses file descriptor as an argument?
a) read
b) write
c) close
d) read, write, close
View Answer

Answer: d
Explanation: A file descriptor is an integer which is allocated when a file is opened. It is used by all system calls that perform some operations on file -like read, write, close, lseek.

Sanfoundry Global Education & Learning Series – Unix.

To practice basic questions and answers on 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.