Basic CS-Operating System [3i Infotech Placement]: Sample Questions 27 - 28 of 89

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 27

Operating System

Question

MCQ▾

Semaphore is used for

Choices

Choice (4)

a.

dead-lock avoidence

b.

box

c.

synchronization

d.

None of the above

Answer

c.

Explanation

Understanding of Semaphore
  • Semaphore is a simple variable used which uses critical sections to achieve process synchronization in a multi-processing environment.
  • Two common semaphores are:
    • Counting semaphore which takes non-negative integer values
    • Binary semaphore which takes the value .
  • If semaphores are implemented using file descriptors. Semaphore creations are not atomic. Thus if two processes try to create, initialize and use a semaphore at the same time, a race condition is created.
  • They are thus implemented through interrupts or by using test-set operations to achieve atomicity

Question 28

Operating System
Edit

Describe in Detail

Essay▾

What is context switching?

Explanation

Understanding of Context Switching
  • Switching of the CPU from one process or thread to another.
  • Context switch describes a standard procedure followed to “switch” from one task to another.
  • Ensures that the tasks do not conflict- they are given their separate contexts.
  • Critical for providing user-friendly multitasking.
  • Performed entirely in hardware.
  • Allows numerous processes or threads on a single processor.
  • Stores and restores the state of CPU in Process Control block- process execution resumes from the same point at a later time.

Three Situations of Context Switch

  • Multitasking
    • The CPU needs to switch processes in and out of memory.
    • So, more than one process can be running.
  • Kernel/User Switch
    • Switching between user mode to kernel mode.
  • Interrupts
    • When the CPU is interrupted to return data from a disk read.
Three Situations of Context Switch

Developed by: