I once took a BrainBench test on “Unix programming.” The questions seemed to fall into two categories: trivial or nonsensical.
The trivial questions usually involved low level API usage or shell syntax or the like. These I could mostly answer off the top of my head or with a quick look at the man page.
The nonsensical questions seemed to be attempts to assess conceptual knowledge of broader subjects.
Which one of the following is the main advantage of non-blocking I/O?
1) Control never leaves the originating routine.
2) Elements and variables are always reused, even if they are not
3) Routines within a program that use non-blocking I/O are never
concurrent and thus never need locks.
4) Variables do not have to be initialized within any segment or
5) Control passes from one program routine to the next very quickly.
The question is perfectly reasonable, but all of the answer choices are vague and none seem to actually answer the question correctly.
First, Unix doesn't really have “routines,” it has processes and C has functions. Functions are sometimes provided by libraries.
I had to guess that the word “routine” is used to mean “function” or maybe “system call.” Not entirely clear.
I guessed that #5 was probably the best answer, since it was not objectively false. But it didn't seem to objectively express anything; “very quickly” seems subjective.
But if I read choice 5 as:
“Control [returns] from one [system call that initiates I/O]
to the [program] [more] quickly.”
then I could agree with that. It doesn't seem to express the “main advantage” of non-blocking I/O, rather it seems to restate it's definition: I/O calls don't block.
The answer I would have liked to see is:
X) It allows a single thread to utilize concurrency, e.g., concurrent
processing and I/O and/or multiple concurrent I/O operations.
Doing some web searching I found what seems to be the source of the question:
“Programs that use non-blocking I/O tend to follow the rule that every function has to return immediately, i.e. all the functions in such programs are non-blocking. Thus control passes very quickly from one routine to the next.”
Looks like this question was formulated by just grabbing it from a public web page, without any deep understanding of Unix programming.
I was rated as “master level” Unix programmer. Gee whiz!