TCS Papers: Sample Questions 294 - 295 of 502

Examrace Placement Series prepares you for the toughest placement exams to top companies.

Question number: 294

» Languages » C & C Plus Plus

Essay Question▾

Describe in Detail

What are code contracts?

Explanation

  • Code contracts express the code assumptions and statements- behavior of code in a language-neutral way.

  • Contracts included in the form of pre-conditions, post-conditions, and object-invariants.

  • Contracts improve testing by enabling run-time checking, static contract verification, and documentation generation.

  • The System. Diagnostics. Contracts namespace contains static classes used to express contracts.

  • The benefits of code contracts include:

  • Improved testing: provide static contract verification, runtime checking, and documentation generation.

  • Automatic testing tools: generate meaningful unit tests by filtering out meaningless test arguments that do not satisfy preconditions.

  • Static verification: static checker checks for contract violations without running the program. Checks implicit contracts, such as null dereferences and array bounds, and explicit contracts.

  • Reference documentation: Documentation generator augments existing XML documentation files with contract information. Generated documentation pages can also have contract sections.

Question number: 295

» Basic CS » Operating System

Essay Question▾

Describe in Detail

What is meant by arm-stickiness?

Explanation

  • If one or a few processes have a high access rate to data on one track of a storage disk, then they may monopolize the device by repeated requests to that track.

  • This generally happens with most common device scheduling algorithms (LIFO, SSTF, C-SCAN, etc).

  • High-density multisurface disks are more likely to be affected by this than low density ones.

  • Arm stickiness is phenomena in I/O scheduling where the scheduling algorithm continues to service requests at or near the current sector and thus prevents any seeking.

  • The name derives from the arm, which controls the seek head, of the disk being stuck or sticky to a particular part of the platter.

  • In general, minimizing seeking is a positive attribute of I/O scheduling—indeed, minimizing seeking is the primary reason we have I/O schedulers.

  • But if the I/O scheduler aggressively favors requests at or near the current sector and those requests continue to come in, then the system will starve requests at other sectors.

  • Many I/O schedulers, including the basic algorithm we are all taught in OS class, called elevator or SCAN, suffer from some amount of arm stickiness.

  • There are several ways to mitigate this.

  • One is using dual queues as in the FSCAN algorithm.

  • In FSCAN, new requests are stored in a second queue and aren’t serviced until the first queue is exhausted.

  • Then the queues flip. This prevents requests at the current sector from preventing seeking.

  • A second solution is to implement deadlines, as in Linux’s deadline I/O scheduler.

  • The deadlines prevent requests from going unserved for a configurable period, forcing a seek once the deadline passes.