Unix Questions and Answers – System Calls Basics – 1

This set of Unix Multiple Choice Questions & Answers (MCQs) focuses on “System Calls Basics – 1”.

1. A system call is a routine built into the kernel and performs a basic function.
a) True
b) False
View Answer

Answer: a
Explanation: All UNIX systems offer around 200 special functions known as system calls. A system call is a routine built into the kernel and performs a very basic function that requires communication with the CPU, memory and devices.

2. When we execute a C program, CPU runs in ____ mode.
a) user
b) kernel
c) supervisory
d) system
View Answer

Answer: a
Explanation: When we execute a C program, the CPU runs in user mode. It remains it this particular mode until a system call is invoked.

3. In ____ mode, the kernel runs on behalf of the user.
a) user
b) kernel
c) real
d) all
View Answer

Answer: b
Explanation: Whenever a process invokes a system call, the CPU switches from user mode to kernel mode which is a more privileged mode. The kernel mode is also called as supervisor mode. In this mode, the kernel runs on behalf of the user and has access to any memory location and can execute any machine instruction.
advertisement
advertisement

4. All UNIX and LINUX systems have one thing in common which is ____
a) set of system calls
b) set of commands
c) set of instructions
d) set of text editors
View Answer

Answer: a
Explanation: As we know that, all UNIX and LINUX systems have one thing in common; they use the same set of system calls.

5. The chmod command invokes the ____ system call.
a) chmod
b) ch
c) read
d) change
View Answer

Answer: a
Explanation: Many commands and system calls share the same names. For example, the chmod command invokes the chmod system call.
Note: Join free Sanfoundry classes at Telegram or Youtube

6. For reading input, which of the following system call is used?
a) write
b) rd
c) read
d) change
View Answer

Answer: c
Explanation: The standard C library offers a set of separate functions to read a block of data. For example, to read a block of data fread is used, for reading a line fgets is used and for reading a character fgetc is used. All these functions invoke the system call -read, which is available for reading input.

7. Which of the following system call is used for opening or creating a file?
a) read
b) write
c) open
d) close
View Answer

Answer: c
Explanation: To read or write to a file, we first need to open it. For this purpose, open system call is used. Open has two forms ; the first forms assumes that the file already exists and the second form creates the file if it doesn’t.
advertisement

8. There are ___ modes of opening a file.
a) 4
b) 3
c) 2
d) 1
View Answer

Answer: b
Explanation: There are three modes of opening a file, out of which only one mode is required to be specified while opening the file. The three modes are, O_RDONLY, O_WRONLY, O_RDWR.

9. Which of the following mode is used for opening a file in both reading and writing?
a) O_RDONLY
b) O_WRONLY
c) O_RDWR
d) O_WDR
View Answer

Answer: c
Explanation: There are three modes of opening a file namely:

advertisement
 O_RDONLY    -    opens files for reading
 O_WRONLY    -    opens file for writing 
 O_RDWR      -   opens file for reading and writing

10. open system call returns the file descriptor as ___
a) int
b) float
c) char
d) double
View Answer

Answer: c
Explanation: open returns the file descriptor as an int. This is the lowest number available for allocation and is used as an argument by the other four calls (read, write, close, lseek).

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.