B.S.W.E. Bachelor of Software Engineering Operating Systems & Systems Programming 2 — Questions and Answers
Question 1: What is the purpose of a semaphore in concurrent programming?
- To allocate memory dynamically
- To control access to a shared resource by multiple threads or processes (Correct answer)
- To detect memory leaks at runtime
- To schedule CPU time for kernel threads
Correct answer: To control access to a shared resource by multiple threads or processes
A semaphore is a synchronization primitive that controls access to shared resources by maintaining a counter and using wait/signal operations.
Question 2: In C programming, what does the 'volatile' keyword indicate?
- The variable is stored in a CPU register
- The variable may be changed by external factors (e.g., hardware or another thread), preventing compiler optimization (Correct answer)
- The variable is immutable after initialization
- The variable is allocated on the heap
Correct answer: The variable may be changed by external factors (e.g., hardware or another thread), preventing compiler optimization
The volatile keyword tells the compiler not to optimize accesses to a variable because its value can change unexpectedly from outside the program's control flow.
Question 3: What is the role of the kernel in an operating system?
- It renders the graphical user interface
- It acts as the core component managing hardware resources and providing services to user programs (Correct answer)
- It compiles source code into machine code
- It manages network connections exclusively
Correct answer: It acts as the core component managing hardware resources and providing services to user programs
The kernel is the core of an OS that manages hardware resources (CPU, memory, I/O), provides system calls, and mediates between software and hardware.
Question 4: Which memory region stores local variables and function call information?
- Heap
- Stack (Correct answer)
- Code segment
- BSS segment
Correct answer: Stack
The stack is used to store local variables, function parameters, and return addresses; it grows and shrinks automatically with function calls.
Question 5: What is a race condition in concurrent programming?
- A scheduling priority given to real-time threads
- A bug where program behavior depends on the relative timing or ordering of uncontrolled events (Correct answer)
- A performance optimization using multiple CPU cores
- A hardware interrupt that preempts a running process
Correct answer: A bug where program behavior depends on the relative timing or ordering of uncontrolled events
A race condition occurs when two or more threads access shared data concurrently and the outcome depends on the non-deterministic order of their execution.
Question 6: What is the purpose of paging in memory management?
- To compress memory contents to save space
- To divide physical memory into fixed-size frames and logical memory into pages, enabling non-contiguous allocation (Correct answer)
- To prioritize memory access for kernel processes
- To replicate memory across multiple processors
Correct answer: To divide physical memory into fixed-size frames and logical memory into pages, enabling non-contiguous allocation
Paging divides both physical and logical memory into fixed-size blocks (frames and pages), eliminating external fragmentation and enabling efficient memory use.
What is the purpose of a semaphore in concurrent programming?