0% found this document useful (0 votes)
37 views33 pages

One Line Ques Ans

The document provides a comprehensive overview of operating systems, including definitions, components, and functionalities such as process management, memory management, and system calls. It discusses various types of systems, including multiprocessor and clustered systems, as well as concepts like time sharing and virtual machines. Additionally, it covers the structure of operating systems and user interfaces, highlighting the importance of system calls and the role of the kernel.

Uploaded by

swapnilruikar45
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views33 pages

One Line Ques Ans

The document provides a comprehensive overview of operating systems, including definitions, components, and functionalities such as process management, memory management, and system calls. It discusses various types of systems, including multiprocessor and clustered systems, as well as concepts like time sharing and virtual machines. Additionally, it covers the structure of operating systems and user interfaces, highlighting the importance of system calls and the role of the kernel.

Uploaded by

swapnilruikar45
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

One Line Answers

Paper 1: System Programming & Operating System


Chapter 1: Introduction
1. Define operating system
It is a program that acts as an interface between the user of a computer and the computer hardware.
2. Define Kernel
An Kernel is one program that is running at all times on the computer and all else are application
programs used to provide an interface between the user program and hardware and manages all the
resources and allocates them to different user program
3. What are the purposes of operating system?
One purpose is to provide an environment for users to execute programs in a convenient and efficient
manner.
Another is to allocate resources to solve problems in a fair and efficient manner.
4. What are the components of the computer system?
1. The hardware
2. The operating system
3. Application programs and
4. The users
5. What is an application program?
The application programs are different kinds of programs written in various languages to solve the
computing problems of users. e.g. Database systems, business programs, games etc.
6. State operating system views.
1. User view
2. System view
7. What is User view of the OS?
The user’s view of OS is to provide convenience to user i.e. provide better environment to user.
8. What is System View of the OS?
The system view of OS is to provide efficiency i.e. manage computer resource is efficient manner.
9. What is Control program?
The operating system acts as control program. As a control program, the operating system manages the
execution of user programs to prevent errors and improper use of computer.
10. What is an Interrupt?
An interrupt is a signal from a device attached to a computer or from a program within the computer that
causes the main program that operates the computer (the operating system ) to stop and figure out what to
do next.
11. What is a trap?
A trap (or an exception) is a software-generated interrupt caused either by an error (for example, division
by zero or invalid memory access) or by a specific request from a user program that an operating-system
service be performed.
12. What is Boot Strap Program?
A bootstrap program is loaded at power-up or reboot. Initializes all aspects of system. Loads operating
system kernel and starts execution.
13. Where Boot Strap Program is generally stored?
Typically stored in ROM or EPROM, generally known as firmware.
14. What is user mode?
When the computer system is executing on behalf of a user application system is in user mode.
15. What is kernel mode?

©net2net 1
One Line Answers
When a user application requests a service from the operating system through system call, it must change
from user to kernel mode. In kernel mode execution is done on behalf of operating system.
16. What is mode bit?
Computer system must ensure that a user could never gain control of the computer system in monitor
mode and privileged instruction can be executed only in system mode or kernel mode. To ensure this, a bit
called mode bit is used. It is added to computer hardware to indicate the current mode.
17. State the usage of the timer
Timer is commonly used to implement time sharing. A counter is set with the amount of time that a
program is allowed to run. As long as counter is positive, control remains with user program. When the
counter becomes zero the operating system terminates the program. Timer is also used to compute the
current time.
18. Operating System is hardware component. Comment and Justify.
Operating system is a program which helps to execute users program effectively on a computer system.
Operating system acts like as intermediate between user of computer and computer hardware.
19. What are Clustered Systems?
Like multiprocessor systems, clustered systems gather together multiple CPUs to accomplish
computational work. Clustered systems are composed of two or more individual systems coupled
together. They share storage and are closely linked via LAN network.
20. Explain the terms Buffer and Cache.
- A buffer is a memory area that stores data while they are transferred between two devices or between
a device and an application.
- A cache is a region of fast memory that holds copies of data.
21. What is single processor system?
Single processor systems have only one main CPU.
22. What is a multiprocessor system? What are the two types of multiprocessor systems?
Multiprocessor system also known as parallel system or tightly coupled system with two or more CPU’s
sharing common RAM. Types of multiprocessor systems: Symmetric Multiprocessor, Asymmetric
Multiprocessor.
23. What are the advantages of multiprocessor systems?
a. Increased throughput
b. Economical
c. Increased reliability
i. Graceful degradation
ii. Fail-soft systems
24. Explain asymmetric multiprocessing.
1. Each processor is assigned a specific task.
2. Master processor schedules and allocates work to slave processors.
3. More common in extremely large systems.
25. Explain the Web Clipping.
It is one approach for displaying the content in web pages, where only a small subset of a web page is
delivered and displayed on the handheld device.
26. What is asymmetric clustering?
Asymmetric clustering: one server runs the application while other servers’ standby.
27. Difference between multiprogramming and multiprocessor system.
In multiprogramming environment user can execute more than one program concurrently. In
multiprocessor system more than one CPU work in communication sharing common RAM.
28. List the advantages of distributed system.
1. Computation speed up
2. Increased data availability

©net2net 2
One Line Answers
3. Enhanced reliability
4. Efficient functionality
29. What is graceful degradation?
This ability to continue providing service proportional to the level of surviving hardware is called
graceful degradation.
30. What is Fault Tolerance?
Systems designed for graceful degradation are also called fault tolerant
31. What are types of clustered system?
1. Asymmetric clustering: one server runs the application while other servers’ standby.
2. Symmetric clustering: all N hosts are running the application.
32. What is Multiprogramming?
Multiprogramming organizes jobs (code and data) so CPU always has one to execute. A subset of total
jobs in system is kept in memory. One job selected and run via job scheduling. When it has to wait (for
I/O for example), OS switches to another job
33. What features are needed in operating system for multiprogramming?
1. I/O routine supplied by the system
2. Memory management
3. CPU scheduling
4. Allocation of devices
34. What is time sharing?
Time sharing (or multitasking) is a logical extension of multiprogramming. The CPU executes multiple
jobs by switching among them, but the switches occur so frequently that the users can interact with each
program while it is running.
35. What features are needed in operating system for time sharing?
1. File system must be available for user to access data and code
2. Memory management
3. CPU scheduling
4. Job synchronization and have communication facilities.
5. Ensure that dead lock in define waiting time doesn’t occur.
6. All sharing of computer resources.
36. Give storage devices hierarchy according to speed and cost.

37. State Different components of the operating system.


©net2net 3
One Line Answers
1. File manager
2. Process, thread and resource manager
3. Memory manager
4. Device manager
38. List the activities performed by the OS in process management.
1. Creating and deleting both user and system processes
2. Suspending and resuming processes/ process scheduling
3. Providing mechanisms for process synchronization
4. Providing mechanisms for process communication
5. Providing mechanisms for deadlock handling
39. List the activities performed by the OS to memory management.
1. Keeping track of which parts of memory are currently being used and by whom
2. Deciding which processes (or parts) and data to move into and out of memory
3. Allocating and deallocating memory space as needed
40. List the activities performed by the OS to file system management.
1. Creating and deleting files and directories
2. Primitives to manipulate files and directories
3. Mapping files onto secondary storage
4. Backup files onto stable (non-volatile) storage media
41. List the activities performed by the OS to mass storage management.
1. Free-space management
2. Storage allocation
3. Disk scheduling
42. What is index register?
The internal programmable registers, such as index registers, provide a high-speed cache for main
memory.
43. Why cache management is important?
Because caches have limited size, cache management is an important design problem. Careful selection of
the cache size and of a replacement policy can result in 80 to 99 percent of all accesses being in the cache,
greatly increasing performance.
44. What is cache coherency?
In a multiprocessor environment in addition to maintaining internal registers, each of the CPUs also
contains a local cache. A copy of data may exist simultaneously in several caches. Since the various CPUs
can all execute concurrently, we must make sure that an update to the value in one cache is immediately
reflected in all other caches. This situation is called cache coherency
45. What is compute-server system?
Compute-server provides an interface to client to request services (i.e. database)
46. What is file server system?
File-server provides interface for clients to store and retrieve files
47. What is open-source operating system?
Operating systems made available in source-code format rather than just binary closed-source
Examples include GNU/Linux, BSD UNIX (including core of Mac OS X), and Sun Solaris
48. List different computing environments
1. Traditional computing
2. Client-server computing
3. Peer to peer computing
4. Web based computing

©net2net 4
One Line Answers
Chapter 2: System Structure
1. Define booting
The procedure of starting a computer by loading the kernel is known as booting the system.
2. What is bootstrap loader
A small program known as the bootstrap program or bootstrap loader locates the kernel, loads it into main
memory and starts its execution.
3. What is shell?
On some operating system, multiple command interpreters are available to choose, these interpreters are
known as shells.
4. What are the two models used in inter-process communication?
1. Shared memory model
2. Message passing model
5. What is system call?
Operating system provides services by means of system calls. System calls provide the interface between
a running program and the operating system.
6. List the different ways to pass parameters to the operating system in a system call.
1. Pass the parameters in registers
2. Parameters stored in a block, or table, in memory, and address of block passed as a parameter in a
register
3. Parameters placed, or pushed, onto the stack by the program and popped off the stack by the operating
system
7. Write any four operating system services.
1. Program execution
2. I/O operations
3. File-system manipulation
4. Communications
5. Error detection.
8. How system calls are supported by Microsoft windows?
Microsoft Windows supports systems calls in form of Win32 APIs. The API (application program
interface) specifies a set of functions that are available to an application programmer, including the
parameters that are passed to each function and the return values the programmer can expect.
9. State the purpose of Command Interpreter.
It reads commands from the user or from a file of commands and executes them, usually by turning them
into one or more system calls. It is usually not part of the kernel since the command interpreter is subject
to changes.
10. Why command interpreter is usually separate from Kernel?
It is usually not part of the kernel since the command interpreter is subject to changes.
11. List any two systems calls for information maintenance.
1. get time or date, set time or date.
2. get system data, set system data.
3. get process, file, or device attributes.
4. set process, file, or device attributes.
12. List different types of systems programs.
1. File management
2. Status information
3. File modification
4. Programming language support
5. Program loading and execution

©net2net 5
One Line Answers
6. Communication
13. List any 4 process control system calls.
1. create process, terminate process
2. end, abort
3. load, execute
4. get process attribute, set process attribute
5. wait time, signal event
6. allocate and free memory
14. List any four Device Management System calls.
1. request device, release device
2. read, write, reposition
3. get device attribute, set device attributes
4. logically attach or detach devices
15. List any four file management system calls.
1. create file, delete file
2. open, close
3. read, write, reposition
4. get file attributes, set file attributes
16. List any four communication system calls.
1. create, delete communication connection
2. send, receive messages
3. transfer status information
4. attach or detach remote devices
17. List protection system calls.
1. The set permission and get permission manipulate the permission settings of resources such as files
and disks.
2. The allow user and deny user system calls, specify whether particular users can or cannot be allowed
to access to certain resources.
18. What is Batch Interface?
This is non-interactive user interface, commands and directives to control those commands are stored into
files (batch files) and those files are executed.
19. What is Graphical User interface (GUI)?
Most commonly user interface. It accepts inputs via devices such as computer keyboard and mouse and
provides articulated graphical output on the computer monitor.
20. List the services provided by the OS to help user.
1. User interface
2. Program execution
3. I/O operations
4. File system manipulation
5. Communication
6. Error detection
21. List the services provided by the OS to help the system operation.
1. Resource allocation
2. Accounting
3. Protection and security
22. List two approaches by which the user can interact with the OS
1. Command line interpreter

©net2net 6
One Line Answers
2. Graphics User Interface (GUI)
23. What are the different OS structures?
1. Simple structure
2. Layered structure
3. Micro-kernels
4. Modules
24. What is virtual machine?
A virtual machine (VM) is a software implementation of a machine (i.e. a computer) that executes
programs like a physical machine.
25. What are the benefits of using virtual machine?
1. Each VM is completely isolated from all other VMs, so no protection is needed.
2. Resources are shared indirectly.
3. System programmer can use their own VM to develop system on VM.

Chapter 3: Process Management


1. What is Process? List the different types of process.
A process is a program in execution. Different types of process are: I/O bound process and CPU bound
process.
2. What does every process includes?
o The program code (text section)
o The program counter and the contents of the processor’s registers.
o The process stack, containing temporary data (sub-routine parameters, return addresses, and
temporary variables)
o A data section containing global variables.
3. What do you mean by passive entity and active entity?
Program is a passive entity and process is a active entity.
4. Define I/O bound process
The process that spends most of its time doing I/O than computations
5. Define CPU bound process
The process that generates and I/O request less frequently and uses much of its time doing computations.
6. Define Job queue
Set of all processes in the system.
7. Define Ready queue
Set of all processes residing in main memory, ready and waiting to execute.
8. Define Device queue
Set of processes waiting for an I/O device.
9. List the process states
Different process states are: new, running, waiting, ready and terminated.
10. Draw a process state diagram.

©net2net 7
One Line Answers
11. Define PCB
Each process is represented in the operating system by a process control block (PCB)-also called a task
control block. It contains many pieces of information associated with a specific process.
12. Draw a neat, labeled diagram of process Control Block.

13. What do you mean by context switch?


Switching the CPU to another process requires saving the state of the old process and loading the saved
state for the new process. This task is known as a context switch.
14. What is “Cascading Termination” of Processes?
If a process terminates (either normally or abnormally), then all its children must also be terminated. This
phenomenon is referred to as cascading termination.
15. What are the two possibilities exist in terms of execution when process creates a new process?
1. Parent and children execute concurrently
2. Parent waits until children terminate
16. State different types of scheduler.
1. Short-term scheduler
2. Long-term scheduler
3. Medium-term scheduler
17. Write primary function of medium term scheduler.
The primary function of medium term scheduler is to swap-out partially executed processes and again
swap-in as and when required.
18. What is the degree of multiprogramming? Which scheduler determines the degree of
multiprogramming?
Degree of multiprogramming is number of processes in memory. Long term scheduler determines degree
of multiprogramming.
19. “Long term scheduler controls the degree of multiprogramming” yes/no-Justify.
Yes – Long term scheduler maintains degree of multiprogramming by making proper process mix of
CPU-bound and I/O-bound jobs.
20. Define parent process
A process creates several new processes, using create process system call, during execution. Such a
process is called as parent process.
21. Define child process
The processes created by parent processes are called as child processes. These processes in turn can create
further new processes and become parent of created processes.
22. What is process identifier?
The processes are identified by unique number given at the time of creation of the process which is called
as process identifier or pid.
23. Define independent process

©net2net 8
One Line Answers
A process is independent if it cannot affect or can be affected by the other processes executing in the
system i.e. process that does not share any data (temporary or persistent) with any other process is
independent.
24. Define co-operating process
A process is cooperating if it can affect or can be affected by the other processes executing in the system
i.e. process that shares data with other processes is a cooperating process.
25. What does short term scheduler do?
The short-term scheduler, or CPU scheduler, selects from among the processes that are ready to execute,
and allocates the CPU to one of them.
26. execlp( ) system call is used generally after the fork() system call. Comment.
True – The child process by default gets the duplicate address space as that of the parent. So to replace
that address space with the new address space for the child, execlp() system call is used after fork()
system call.
27. What is the purpose of the following system calls?
a. fork( ) – Used to create new process
b. wait ( ) – Waits for specific child process
c. execlp( ) – Replaces the current process image with new process image
28. What actions are taken upon receiving the exit() system call?
1. Output data from child to parent (via wait)
2. Process’ resources are deallocated by operating system
29. What are the different reasons for which a client can terminate any of its children?
1. Child has exceeded allocated resources
2. Task assigned to child is no longer required
3. If parent is exiting: Some operating system do not allow child to continue if its parent terminates
30. What is a need of process co operation?
1. Information sharing
2. Computation speedup
3. Modularity
4. Convenience
31. What are the models for inter-process communication?
1. Shared memory model
2. Message passing model
32. What are the advantages of shared memory systems?
1. It allows maximum speed and convenience of communication as it can be done at memory speeds.
2. Once shared memory is established all accesses to shared memory are treated as routine memory
accesses and no kernel assistance is required.
33. What is a producer consumer problem?
It is used to illustrate the concept of cooperating processes. A producer process produces information that
is consumed by a consumer process.
e.g. A print program produces characters that are consumed by the printer device drivers.

Chapter 4: Multithreaded Programming


1. What is a thread?
A thread, also called a lightweight process (LWP), is a basic unit of CPU utilization; it comprises a thread
ID, a program counter, a register set, and a stack. It shares with other threads belonging to the same
process its code section, data section, and other operating-system resources, such as open files and signals.
2. What are the drawbacks of “Heavy-weight processes”?

©net2net 9
One Line Answers
Heavy-weight processes have a significant amount of over head when switching. All the tables have to be
flushed from the processor for each task switch. If a HWP spawns a child HWP using fork(), the only part
shared is the text.
3. List the advantages of multithreaded programming.
1. Responsiveness
2. Resource sharing
3. Economy
4. Utilization of multiprocessor architectures
4. What different multithreaded models are there?
1. Many-to-One Model
2. One-to-one Model
3. Many-to-Many Model
5. What are the types of thread?
1. User thread
2. Kernel thread
6. Define user thread
User level thread or user thread avoids the kernel and manages the table itself. These threads are
implemented in user level libraries rather than via system calls.
7. Define kernel thread
Kernel-level threads or kernel threads are supported and managed by the operating system.
8. What is thread libraries?
A thread library provides the programmer an API for creating and managing threads.
9. What are two ways to implement thread libraries:
1. Provide thread library entirely in user space without kernel support.
2. Provide thread library in kernel space supported by the operating system.

Chapter 5: Process Scheduling


1. List the different scheduling algorithms
1. FCFS (First Come First Serve)
2. SJF (Shortest Job First)
3. Priority
4. Round Robin
5. Multilevel Queue Scheduling
6. Multilevel Feedback Queue Scheduling
2. Write the purpose of CPU scheduling algorithms.
The purpose of CPU scheduling is to maximize the utilization of the CPU. In order to do this, a process
should be running at all times. For example, if a process is waiting for some event to occur before it is
able to continue execution, then it should not have control of the CPU. If it does, then the CPU is being
wasted.
3. Which CPU scheduling algorithm is used in Microsoft Windows 2000?
Microsoft Windows 2000 uses priority based preemptive scheduling. Separate queue for each priority and
scheduled in RR manner.
4. Which CPU scheduling Algorithm is used by Linux for conventional time shared processes?
Linux for conventional time shared processes uses prioritized, credit based scheduling. Scheduler chooses
the process with the most credits.
5. “Round-Robin algorithm is non-preemptive”. Comment and justify.

©net2net 10
One Line Answers
Round-Robin algorithm is FCFS with preemption. Each process gets a small unit of CPU time (time
quantum), usually 10-100 milliseconds. After this time has elapsed, the process is preempted and added to
the end of the ready queue.
6. What is “dispatcher”? What are the functions performed by dispatcher?
The dispatcher is the module that gives control of the CPU to the process selected by the short-term
scheduler.
Functions of dispatcher:
• Switching context
• Switching to user mode
• Jumping to the proper location in the user program to restart that program
7. Define the term ‘Processor sharing’.
The performance of the RR algorithm depends heavily on the size of the time quantum. If the time
quantum is very small (say 1 microsecond), the RR approach is called processor sharing, and appears (in
theory) to the users as though each of n processes has its own processor running at l/n the speed of the real
processor.
8. Define dispatch latency time.
The time it takes for the dispatcher to stop one process and start another running is known as the dispatch
latency.
9. What is CPU-Bound process?
A CPU-bound process, generates I/O requests infrequently, using more of its time doing computation
10. “Every process has equal number of CPU-Burst and I/O-Burst” Yes/No. Comment.
No - An I/O-bound program would typically have many very short CPU bursts. An CPU-bound program
might have a few very long CPU bursts.
11. Define the term ‘Response Time’.
Amount of time it takes from when a request was submitted until the first response is produced, not
output (for time-sharing environment)
12. Define CPU burst.
In the process execution the cycle of CPU execution is called as CPU burst.
13. Define I/O burst.
In the process execution the cycle of I/O is called as I/O burst
14. Define CPU scheduler.
There are several processes in ready queue waiting to be scheduled by CPU. Whenever CPU becomes
idle, the operating system selects one of these processes and allocates CPU to that process. The selection
is done by CPU scheduler.
15. Define CPU Utilization
CPU utilization is the range that the CPU is busy. Normally this range is 0 to 100%. But in real systems,
this range varies from 40% for lightly loaded systems and 90% for heavily loaded system.
16. Define Throughput.
Throughput is the number of processes that are completed per time unit.
17. Define Turnaround time.
The interval from the time of submission of a process to the time of completion is the turnaround time.
Turnaround time is the sum of the periods spent waiting to get into memory, waiting in the ready queue,
executing on the CPU, and doing I/O.
18. Define Waiting time.
Waiting time is the sum of the periods spent waiting in the ready queue.
19. Define Arrival time or submission time.
It is the time at which the process is submitted to the system for the first time and is in hold state.
20. Define Start time.

©net2net 11
One Line Answers
It is the time at which the process is selected by short-term scheduler and is allocated to CPU. It is the
time at which the process starts its execution.
21. Define end time or finish time.
It is the time at which the process finishes its execution.
22. What is convoy effect?
When all the other processes wait for the one big process to get off the CPU then this effect is called as
convoy effect. It results in lower CPU and device utilization than might be possible if the shorter
processes were allowed to go first.
23. Define: Process-contention scope (PCS)
Scheduling technique used to schedule user-level threads belonging to the same process
24. Define: System-contention scope (SCS)
Scheduling technique used to schedule kernel-level threads to the CPUs
25. Define Pthreads.
Refers to the POSIX standard defining an API for thread creation and synchronization. This is a
specification for thread behavior, not an implementation. Operating system designers may implement the
specification in any way they wish.
26. POSIX Pthread API.
It allows specifying either PCS or SCS during thread creation.
27. Pre-emptive and non pre-emptive scheduling.
Under nonpreemptive scheduling, once the CPU has been allocated to a process, the process keeps the
CPU until it releases the CPU either by terminating or by switching to the waiting state.
Under preemptive scheduling, the CPU can be taken back from the process forcibly by a new process.
28. State the criteria when the CPU scheduling decisions take place for a process.
1. Switches from running to waiting state.
2. Switches from running to ready state.
3. Switches from waiting to ready.
4. Terminates.
29. State when pre-emptive and non pre emptive scheduling will take place?
When a process switches from the running state to the waiting state or when process terminates then non-
preemptive scheduling takes place and when a process switches from the running state to the ready state
when a process switches from the waiting state to the ready state preemptive scheduling takes place.
30. An algorithm is more efficient if the throughput is more. Comment.
True – Algorithm is said to efficient if it keeps CPU busy as much as possible. If CPU is busy ultimately
throughput of the system also increases (i.e. number of task completed per time unit).
31. Good operating system always produces minimum response time. State true or false and Justify
your answer.
True - Operating-system developers implement scheduling by maintaining a queue of requests for each
device. When an application issues a blocking I/O system call, the request is placed on the queue for that
device. The I/O scheduler rearranges the order of the queue to improve the overall system efficiency and
the average response time experienced by applications.
32. What do you mean by internal priority and external priority?
Internally defined priorities use some measurable quantity or quantities to compute the priority of a
process. For example, time limits, memory requirements, the number of open files, and the ratio of
average I/O burst to average CPU burst have been used in computing priorities.
External priorities are set by criteria that are external to the operating system, such as the importance of
the process, the type and amount of funds being paid for computer use, the department sponsoring the
work, and other, often political, factors.
33. What is infinite blocking or starvation problem?
A process that is ready to run but lacking the CPU can be considered blocked-waiting for the CPU. A
priority-scheduling algorithm can leave some low-priority processes waiting indefinitely for the CPU.

©net2net 12
One Line Answers
34. What is aging? Where it is used?
Aging is a technique of gradually increasing the priority of processes that wait in the system for a long
time. A solution to the problem of indefinite blockage of low-priority processes is aging.
35. What are the parameters used to define the multilevel feedback queue scheduling
1. The number of queues
2. The scheduling algorithm for each queue
3. The method used to determine when to upgrade a process to a higher priority queue
4. The method used to determine when to demote a process to a lower-priority queue
5. The method used to determine which queue a process will enter when that process needs service
36. Which contention scope values are identified by Pthreads?
1. PTHREAD SCOPE PROCESS schedules threads using PCS scheduling
2. PTHREAD SCOPE SYSTEM schedules threads using SCS scheduling.
37. Which functions are provided by the Pthread IPC for getting and setting the contention scope
policy?
pthread_attr_setscope(pthread_attr_t *attr, int scope)
pthread_attr_getscope(pthread_attr_t *attr, int *scope)

Chapter 6: Process Synchronization


1. State the requirements which should be satisfied by a solution to the critical section problem.
A solution to the critical-section problem must satisfy the following three requirements:
1. Mutual exclusion. 2. Progress. 3. Bounded waiting.
2. What do you mean by mutual exclusion?
If process Pi is executing in its critical section, then no other processes can be executing in their critical
sections.
3. “Process Synchronization is an integral part of MS-DOS”. Justify.
DOS was only able to run one process at a time. The single process would be spawned in a single thread
of execution. For this reason there was no need for both kernel level and user-level threading because all
processes ran in same type of thread. Mutual exclusion and needs for synchronization were not needed
because only one process had control of the entire system at any given time.
4. Explain the term Bounded wait.
A bound must exist on the number of times that other processes are allowed to enter their critical sections
after a process has made a request to enter its critical section and before that request is granted.
5. Explain the term progress
If no process is executing in its critical section and some processes wish to enter their critical sections,
then only those processes that are not executing in their remainder section can participate in the decision
on which will enter its critical section next, and this selection cannot be postponed indefinitely.
6. What is critical section of process?
Each process has a segment of code, called a critical section, in which the process may be changing
common variables, updating a table, writing a file, and so on.
7. Define Race condition
When several processes access and manipulate the same data concurrently and the outcome of the
execution depends on the particular order in which the access takes place, is called a race condition.
8. Entry section.
Each process must request permission to enter its critical section. The section of code implementing this
request is the entry section.
9. Exit section.
The critical section may be followed by an exit section.
10. Remainder section.

©net2net 13
One Line Answers
The code following exit section i.e. remaining code after exit section is called as remainder section.
11. Preemptive kernel.
A preemptive kernel allows a process to be preempted white it is running in kernel mode.
12. Non Preemptive Kernel.
A non preemptive kernel does not allow a process running in kernel mode to be preempted. It is free from
race condition.
13. What is a Semaphore?
A semaphore is a synchronization tool. A semaphore S is an integer variable that can only be accessed via
two indivisible (atomic) operations: wait and signal
wait (S): while S≤0; // no-op
S--;
signal (S): S++;
Only one process may modify S at a time
14. Why process synchronization is needed?
Concurrent access to the shared data may result in inconsistency. In multi-process environment, to ensure
only one process is manipulating shared data we need process synchronization is needed.
15. List different solutions available to solve critical section problem.
1. Software based solution is known as Peterson’s solution
2. Hardware base solution uses a tool – a lock.
3. TestAndSet() instruction and Swap() instructions.
4. Semaphore
16. What is spinlock?
Semaphore requires busy waiting. This busy waiting wastes CPU cycles. This type of semaphore is also
called as spinlock.
17. What is bounded buffer problem?
1. There is a fixed buffer size.
2. The consumer must wait if the buffer is empty and the producer must wait if the buffer is full.
18. What is reader-writers problem?
1. A data object is shared among several processes
2. Readers: processes that want only to read the shared object
3. Writers: processes that want to write the shared object
4. It’s OK for more than one readers to access the shared object simultaneously
5. If a writer accesses the shared object, then it must have exclusive access
19. What is dinning philosopher problem?
1. When a philosopher gets hungry, he tries to pick up the left and right chopsticks
i. Can pick up one chopstick at a time
2. When a philosopher is finished eating, he puts down both chopsticks
20. What are the types of semaphore?
1. Binary semaphore: takes on only the values 0 and 1.
2. Counting semaphore: can rage over an unrestricted domain.
21. List different classic problems of synchronization
1. Bounded-buffer producer consumer problem
2. Reader-writers problem
3. Dinning philosopher problem
22. What are the solutions to Dining Philosophers problem?
1. Allow at most 4 philosophers to be sitting at the table
2. Allow a philosopher to pick up his chopsticks only if both chopsticks are available

©net2net 14
One Line Answers
3. Use an asymmetric solution: an odd philosopher picks up first his left chopstick and then his right
chopstick, an even philosopher picks up first his right chopstick and then his left chopstick

Chapter 7: Deadlocks
1. Define deadlock.
Deadlock is a situation in a set of blocked processes each holding a resource and waiting to acquire a
resource held by another process in the set.
2. In which sequence, a process utilizes resources?
Each process utilizes a resource as follows:
b. request
c. use
d. release
3. What is system table?
A system table records whether each resource is free or allocated, and, if a resource is allocated, to which
process.
4. What is ‘rollback’?
Preempting resources of process bringing it to safe state and restart it from that state is called rollback.
5. What is a Resource Allocation Graph?
The RAG consists of a set of vertices P={P1,P2,…,Pn} of processes and R={R1,R2,…,Rm} of resources. A
directed edge from a process to a resource, PiRj, implies that Pi has requested Rj. A directed edge from a
resource to a process, RjPi, implies that Rj has been allocated by Pi.
6. What is a claim edge in Resource Allocation Graph?
Claim edge Pi → Rj indicated that process Pi may request resource Rj represented by a dashed line. Claim
edge converts to request edge when a process requests a resource.
7. List the issues that must be addressed when resource is preempted to break deadlock.
1. Selecting victim
2. Rollback
3. Starvation
8. Define safe state
A state is safe if the system can allocate maximum resources to each process in some order and still avoid
a deadlock.
9. Define safe sequence
A sequence of processes <P1, P2, ..., Pn> is a safe sequence for the current allocation state if, for each Pi,
the resources that Pi can still request can be satisfied by the currently available resources plus the
resources held by all the Pj, with j < i.
10. Discuss the symbols used for representation of resource allocation graph.
Pictorially, we represent each process Pi as a circle, and each resource type Ri as a square. Since resource
type Ri may have more than one instance, we represent each such instance as a dot within the square. Note
that a request edge points to only the square Ri, whereas an assignment edge must also designate one of
the dots in the square.
11. What are the disadvantages of safe state method of deadlock avoidance?
Resource utilization may be lower than it would be without a deadlock-avoidance algorithm.
12. Give limitation of resource allocation graph method of deadlock avoidance.
Resource allocation graph method of deadlock avoidance can’t be applied to resources with multiple
instances.
13. List the data structures used in Bankers algorithm.
n – number of processes
m – number of resource types
available[m]

©net2net 15
One Line Answers
max[n,m]
allocation[n.m]
need[n,m]
14. List the data structures used in resource request algorithm.
n – number of processes
m – number of resource types
available[m]
max[n,m]
allocation[n.m]
need[n,m]
request[m]
15. What is wait-for graphs?
If all resources have only a single instance, then we can define a deadlock detection algorithm that uses a
variant of the resource-allocation graph, called a wait-for graph. We obtain this graph from the resource-
allocation graph by removing the nodes of type resource and collapsing the appropriate edges.

Chapter 8: Memory Management


1. Define cache memory
Fast memory between CPU and main memory is called as cache memory.
2. Define base register
Stores the smallest legal physical memory address
3. Define limit register
Limit register contains the size of the range.
4. What is compile time binding
If it is known at compile time where the process will reside in memory, then absolute code can be
generated.
For example, if it is known a priori that a user process resides starting at location R, then the generated
compiler code will start at that location and extend up from there.
If at some later time, the starting location changes, then it will be necessary to recompile the code.
The MS-DOS.COM-format programs are absolute code bound at compile time.
5. What is load time binding
If it is not known at compile time where the process will reside in memory, then the compiler must
generate relocate code. In this case, the final binding is delayed until load time. If the starting address
changes, we need only to reload the user code to incorporate this changed value.
6. What is execution time binding
If the process can be moved during its execution from one memory segment to another, then binding must
be delayed until run time. Need hardware support for address maps (e.g., base and limit registers).
7. What is logical address?
It is the address generated by the CPU. Also referred to as virtual address.
8. What is physical address?
It is the address seen by the memory management unit (MMU).
9. Give on major function of MMU.
The memory management unit (MMU) is a hardware device that maps virtual to physical address. It
converts logical address to physical address.
10. What is dynamic loading?
A routine or sub-program is not loaded until it is called is called as dynamic loading.
11. What is static linking?

©net2net 16
One Line Answers
System language libraries are treated like any other object module and are combined by the loader into the
binary program image is called as static linking
12. What is dynamic linking?
System language libraries are not linked at the time of loading but the linking is postponed until execution
time.
13. What is a hole?
A free contiguous block of available memory is called as hole.
14. What is page?
The logical memory is divided into blocks of same size called as pages.
15. What is frame?
The physical memory is divided into fixed size blocks called frames.
16. What is swapping?
Swapping means temporarily moving process out of memory to a backing store and then bring back into
memory for continued execution.
17. What is the use of cache memory?
The CPU uses cache memory to store instructions that are repeatedly required to run programs, improving
overall system speed. The advantage of cache memory is that the CPU does not have to use
the motherboard’s system bus for data transfer.
18. What is ASID?
An ASID uniquely identifies each process and is used to provide address space protection for that process.
When the TLB attempts to resolve virtual page numbers, it ensures the ASID for the currently running
process matches the ASID associated with the virtual page. If the ASIDs do not match, they are treated as
a TLB miss.
19. What is PTBR
If the page table to be very large (for example, 1 million entries), the use of fast registers to implement the
page table is not feasible. Rather, the page table is kept in main memory, and a page-table base register
(PTBR) points to the page table.
20. What is segmentation?
Segmentation is a memory management scheme that supports the user view of memory.
21. What is sparse address space?
Virtual address spaces that include holes are known as sparse address spaces.
22. What is demand paging?
A strategy to initially load only those pages which are needed is known as demand paging and is
commonly used in virtual memory system.
23. What is pure demand paging?
Start executing a process with no pages in memory. When the operating system sets the instruction pointer
to the first instruction of the process, which is on a non-memory-resident page, the process immediately
faults for the page. After this page is brought into memory, the process continues to execute, faulting as
necessary until every page that it needs is in memory. At that point, it can execute with no more faults.
This scheme is pure demand paging: Never bring a page into memory until it is required.
24. What is TLB miss?
If the page number is not in the TLB then it is known as a TLB miss.
25. Explain Best Fit Allocation Algorithm
Allocate the smallest hole that is big enough. We must search the entire list, unless the list is ordered by
size. This strategy produces the smallest leftover hole.
26. Write one major difference between internal and external fragmentation.
1. Internal fragmentation is the area in a region or a page that is not used by the process it is allocated to.
The space is wasted until the process terminates.
2. External fragmentation occurs when there is enough free space to satisfy a request for memory, but
none of the free "holes" between processes in memory is large enough to satisfy the request.

©net2net 17
One Line Answers
27. What do you mean by Page fault?
If the process tries to access a page that was not brought into memory causes a page-fault trap. This trap is
the result of the operating system's failure to bring the desired page into memory.
28. What is thrashing?
When page fault occurs consecutively for more number of times then this hard paging activity is called
thrashing. In this process, system is spending its more time on paging than executing. Thrashing decreases
performance of system.
29. Define hit ratio
The percentage of times that a page number is found in the associative registers is called the hit ratio.
30. What is Belady’s Anomaly?
Belady’s anomaly reflects the fact that, for some page-replacement algorithms, the page-fault rate may
increase as the number of allocated frames increases.
31. What is re-entrant code?
Reentrant code is non-self-modifying code; it never changes during execution. Thus, two or more
processes can execute the same reentrant code at the same time.
32. “Paging suffers from External Fragmentation”. Comment and justify.
When we use a paging scheme, we have no external fragmentation: Any free frame can be allocated to a
process that needs it.
33. What are zero-fill-on-demand pages?
When a page is to be duplicated using copy-on-write, it is important to see that the free page allocated to it
is zeroed out i.e. its contents have been overwritten with zeros. This is called zero-fill-on-demand.
34. Which page replacement algorithm suffers from Belady’s Anomaly?
FIFO page replacement algorithm suffers from Belady’s anomaly.
35. List the different strategies used to select a free hole in dynamics storage allocation.
1. First-fit
2. Best-fit
3. Worst-fit
36. Define the term ‘backing-store’
It is a fast disk large enough to accommodate copies of all memory images for all users, and provides
direct access to these memory images.
37. What is meant by “Transient code’?
The operating system contains code and buffer space for device drivers. If a device driver is not
commonly used, it is not desirable to keep it in memory, as we might be able to use that space for other
purpose. Such code is called as transient operating system code; it comes and goes as needed.
38. What do you mean by swap-out and swap-in process?
A multiprogramming environment with a RR CPU-scheduling algorithm when a quantum expires, the
memory manager will start to swap-out the process that just finished, and swap-in another process to the
memory space has been freed.
39. What is Roll-out-Roll-in swapping?
In a priority-based scheduling algorithm if a higher-priority process arrives and wants service, the
memory manager can swap-out (roll-out) the lower-priority process so that it can load and execute the
higher-priority process. When the higher-priority process finishes, the lower-priority process can be swap-
in (roll-in) and continued.
40. State 50-percent rule.
Depending on the total amount of memory storage and the average process size, external fragmentation
may be a minor or a major problem. Statistical analysis of first fit, for instance, reveals that, even with
some optimization, given N allocated blocks, another 0.5N blocks will be lost due to fragmentation. That
is, one-third of memory may be unusable! This property is known as the 50-percent rule.
41. What is paging?

©net2net 18
One Line Answers
Paging is a memory-management scheme that permits the physical-address space of a process to be
noncontiguous.
42. In paging, how logical address is represented?

43. CPU divided every address in which parts?


Every address (u) generated by CPU is divided into 2 parts:
a. Page no (p) - used as an index into a page table which contains the frame number (f) of page in
physical memory.
b. Page offset (d) - combined with base address to get the physical memory address that is sent to the
memory unit.
44. What is page table? What are its contents?
A page table is the data structure used by a virtual memory system in a computer operating system to
store the mapping between virtual addresses and physical addresses. It contains the physical frame
number (f) of logical page number (p). The frame number is combined with page offset (d) to get physical
address.
45. How do you calculate the page number and page offset?
p = u / page size
d = u % page size
Where u is logical address
46. How do you calculate effective access time?
Associative Lookup = W time unit
Assume memory cycle time = W time unit
Hit ratio = W
Effective Access Time (EAT)= (W + W) W + (2 W + W)(1 – W)
47. What is segment table?
A segment table keeps track of every segment in a particular process. Each entry contains base and limit.
Also contains protection information (sharing allowed, read vs. read/write)
48. What is Virtual memory?
Technique that allows execution of processes that may not be completely in memory. Allows for the user
programs to be larger than physical memory
49. What do you mean by Virtual address space?
The virtual address space for a process is the set of virtual memory addresses that it can use. The address
space for each process is private and cannot be accessed by other processes unless it is shared.
A virtual address does not represent the actual physical location of an object in memory; instead, the
system maintains a page table for each process, which is an internal data structure used to translate virtual
addresses into their corresponding physical addresses.
50. What is the use of valid-invalid bit in paging?
It is a bit attached to each entry in the page table called Valid-invalid bit :
- “valid” indicates that the associated page is in the process’ logical address space, and is thus a legal
page
- “invalid” indicates that the page is not in the process’ logical address space
51. What is reference string?
The string of memory references is called reference string. It can be generated artificially or tracking a
given system and recording the address of each memory reference.

©net2net 19
One Line Answers
52. List different page replacement algorithms
1. FIFO
2. Optimal
3. LRU
4. Second Chance
5. Counting algorithms (MFU, LFU)
53. How is performance of demand paging calculated?
Page Fault Rate 0 ≤ p ≤ 1.0
a. if p = 0, no page faults
b. if p = 1, every reference is a fault
Effective Access Time (EAT) = (1 – p) x memory access + p x (page fault overhead +
swap page out +
swap page in +
restart overhead)
54. What is dirty bit or modify bit?
Page replacement requires 2 page transfers (swap in + swap out). To decrease this overhead associate a
‘dirty’ bit with each page in page table. Initially when page is loaded in memory its dirty bit is set to ‘0’
indicating clean page. When page is modified its dirty bit is set to ‘1’. When page is selected as victim for
replacement check its dirty bit:
a. If it is set then only we swap out that page in backing store
b. Otherwise only swap in desired page.

Chapter 9: File System


1. What is file?
A file is a named collection of related information defined by its creator that is recorded on secondary
storage.
2. What is file pointer?
On systems that do not include a file offset as part of the read and write system calls, the system must
track the last read-write location as a current-file-position pointer. This pointer is unique to each process
operating on the file, and therefore must be kept separate from the on-disk file attributes.
3. List different types of files
1. Executable
2. Object
3. Source code
4. Batch
5. Text
6. Word processor
7. Library
8. Archive
9. Multimedia
10. Print or view
4. Write any four file attributes.
1. Name
2. Identifier
3. Type
4. Location
5. Size

©net2net 20
One Line Answers
6. Protection
7. Time, date, and user identification
5. Write any four operations that can be performed onto the files.
1. Creating a file.
2. Writing a file.
3. Reading a file.
4. Repositioning within a file.
5. Deleting a file.
6. Truncating a file.
6. List different types of directory structure
1. Single-level
2. Two-level
3. Tree
4. Acylic Graph
5. General Graph
7. What is partition?
A disk is used to store file system. A disk can be partitioned into parts. These parts are known as
partitions, slices or minidisks.
8. What is volume?
Volume is a chunk of storage that holds a file system.
9. Explain single level directory.
The simplest way of maintaining directory structure where all the files are contained in the same
directory. Two users cannot give same file name and search time increases when number of files increase.
10. What is link?
Shared files and subdirectories can be implemented in several ways. A common way used by many of the
UNIX systems, is to create a new directory entry called a link. A link is effectively a pointer to another
file or subdirectory.
11. “External fragmentation is present in linked allocation file system”. Comment and justify.
There is no external fragmentation with linked allocation file system, and any free block on the free-space
list can be used to satisfy a request.
12. What are the operations that can be performed on directory?
1. Search for a file
2. Create a file
3. Delete a file
4. List a directory
5. Rename a file
6. Traverse the file system
13. List different disk allocation methods.
1. Contiguous allocation
2. Linked allocation
3. Index allocation
14. What are the advantages of Indexed Allocation?
The advantages of indexed file allocation are:
1. The absence of external fragmentation and
2. The efficiency of random accessing.
15. What are the different file access methods?
1. Sequential access
2. Random access
©net2net 21
One Line Answers
3. Other access method (relative or index sequential access)
16. What are the different free space management methods?
1. Bitmap/bit vector
2. Linked list
3. Counting
4. Grouping
17. Linked allocation method is more reliable than indexed allocation. Justify.
False - Since the files are linked together by pointers scattered all over the disk, consider what would
happen if a pointer were lost or damaged. A bug in the operating-system software or a disk hardware
failure might result in picking up the wrong pointer.
18. What is cluster?
Clusters are collection of blocks i.e. one cluster can be group of four blocks and it is basic disk allocation
unit.
19. What is FAT?
A section of disk at the beginning of each partition is set aside to contain this table. The table has one
entry for each disk block, and is indexed by block number. The directory entry contains the block number
of the first block of the file. The table entry indexed by that block number then contains the block number
of the next block in the file.
20. Give difference between relative path and absolute path
An absolute path name begins at the root and follows a path down to the specified file, giving the
directory names on the path. A relative path name defines a path from the current directory. If the
current directory is root/spell/mail, then the relative path name prtlfirst refers to the same file as does the
absolute path name root/spell/rnail/prtlfivst.
21. What is garbage collector?
Garbage collector traverses entire file system and marks whatever that can be accessed. Whatever is not
marked by garbage collector is then collected onto a list of free space.
22. What is bit vector?
The free-space list is implemented as a bit map or bit vector. Each block is represented by 1 bit. If the
block is free, the bit is 1; if the block is allocated, the bit is 0.
23. How to calculate location of first free block?
To find the first free block, each word in the bit map is checked to see whether that value is not 0. The
first non-0 word is scanned for the first 1 bit, which is the location of the first free block. The calculation
of the block number is
(number of bits per word) x (number of 0-value words) + offset of first 1 bit.
24. What is free space list?
To keep track of free disk space, the system maintains a free-space list. The free-space list records all free
disk blocks-those not allocated to some file or directory. To create a file, we search the free-space list for
the required amount of space, and allocate that space to the new file. This space is then removed from the
free-space list. When a file is deleted, its disk space is added to the free-space list.
25. What is metaslabs?
Sun’s ZFS creates metaslabs to divide the space on the device into some manageable chunks. A volume
may contain hundreds of metaslabs. Each metaslabs has an associated space map.
26. What is a space map?
The space map is a log of all block activity (i.e. allocation and freeing of blocks) in time order, in
counting format.

©net2net 22
One Line Answers
Paper 2: Theoretical Computer Science & Compiler Construction
Chapter 1: Introduction
1. What is translator? Give one example.
It is a system program that takes as input a program written in one programming language (source) and
produces as output a program in another language (target or object). e.g. Compiler
2. Define Complier.
Complier is a program that reads a program written in one language –the source language- and translates
it into an equivalent program in another language- the target language. In this translation process, the
complier reports to its user the presence of the errors in the source program.
3. Define interpreter.
Interpreter is a language processor program that translates and executes source code directly, without
compiling it to machine code.
4. What do you mean by phase of compiler?
A phase is a logically cohesive (inter related) operation that takes as input one representation of the source
program and produces as output another representation.
5. What is front-end and back-end of the compiler?
Front-end consists of those phases that depend primarily on the source program and largely independent
of the target machine.
Back-end consists of those phases that depend on the target machine language and generally those
portions do not depend on the source language, just the intermediate language.
6. List all phases of compiler in sequence.
1. Lexical Analysis 2. Syntax Analysis
3. Semantic Analysis 4. Intermediate Code Generator
5. Code Optimizer 6. Code Generator
7. What is the main difference between phase and pass of a compiler?
A phase is a sub process of the compilation process whereas combination of one or more phases into a
module is called pass.
8. Define pass of a compiler
In an implementation of a compiler, portion of one or more phases are combined into a module called
pass. A pass reads the source program or the output of the previous pass, makes the transformation
specified by its phases and writes output into an intermediate file, which is read by subsequent pass.
9. Define syntax and semantics.
The rules and regulations used to form a language are known as syntax. The meaning given to a
programming construct is known as semantics.
10. What are the classifications of a compiler?
1. Single-pass compiler.
2. Multi-pass compiler.
3. Load and go compiler.
4. Debugging compiler.
5. Optimizing compiler.
11. What is boot strapping?
Suppose we have a new language L, which we want to make available on several machines say ‘A’ & ‘B’.
We might write for machine ‘A’ a small computer CASA that translates a subset S of language L into the
machine or assembly code of A. this compiler is written in a language that is already available on A.
We than write a compiler CSLA in the simple language S. this program when run through CASA, becomes
CALA, the compiler for complete language L, running on machine A and producing object code for A.
CASA
CSLA CALA
This process is called as bootstrapping.

©net2net 23
One Line Answers
12. Define cross-compiler.
When a compiler runs on one machine and produces object code for another machine such a compiler is
called as cross–compiler.
13. What are advantages of bootstrapping?
1. A compiler can be written in the language it compiles.
2. An optimizing compiler can optimize itself.
14. Multipass compilers are preferable over single pass compilers. Comment.
True – A multi-pass compiler can be made to use less space than a single pass compiler, since the space
occupied by the compiler program for one pass can be reused by following pass.
15. What happens during table management of bookkeeping phase of compilation?
The table management, or bookkeeping, portion of the compiler keeps track of the names used by the
program and records essential information about each, such as its type (integer, real, etc.). The data
structures used to record this information is called a symbol table.
16. Good error handling is difficult. Comment.
Good error handling is difficult because certain errors can mask subsequent errors. Other errors, if not
properly handled, can spawn an avalanche of spurious errors.
17. Define: symbol table
Information about source program (identifiers, type, size, etc.) is stored in a data structure called a symbol
table, which is passed to back end.
18. Define: single-pass compiler
In this type of compiler all phases occur during a single pass i.e. a source program is processed only once,
during the translation.
19. Define: multi-pass compiler
While translating source program into target program, we read through a representation of entire source
program multiple times is called as multi-pass compilers.
20. List the functions that compiler.
1. Translate high level language to low level language.
2. Reporting errors and warnings.
21. Which phase of compiler is also known as scanning phase?
Lexical Analyzer
22. Which phase of compiler is also known as parsing phase?
Syntax Analyzer

Chapter 2: Lexical Analysis


1. Give one major function performed by lexical analyzer.
The lexical analyzer scans the input program character by character ad groups the characters into the
lexical units called tokens.
2. Define lexeme:
The character sequence forming a token is called lexeme for the token.
3. What are tokens?
The first phase, called the lexical analyzer, or scanner, separates characters of the source language into
groups that logically belong together; these groups are called tokens. e.g. keywords, identifiers, operators
etc.
4. What do you mean by pattern?
The rules, which characterize the set of strings for a token. Pattern is expressed in terms of regular
expressions. e.g. [a-zA-Z][a-zA-Z0-9]*
5. Name two compiler construction tools
1. LEX
2. YACC
©net2net 24
One Line Answers
6. What is meant by recognizer?
A recognizer for a language L is a program that takes an input string “x” and response “yes” if “x” is
sentence of L and “no” otherwise.
7. Write state program for the token, “id-identifier”.
State-0: C=GETCHAR ();
If LETTER(C) then go to State-1
Else FAIL ();
State-1: C=GETCHAR ();
If LETTER(C) or DIGIT (C) then go to State-1
Else If DELIMITER(C) then go to State-2
Else FAIL ();
State-2: RETRACT ();
return (id, INSTRALL ());
8. “It is desirable for the lexical analyzer to read its input from an input buffer”. Give one reason
supporting the given statement.
The lexical analyzer scans the characters of the source program one at a time to discover tokens. Often,
however, many characters beyond the next token may have to be examined before the next token itself can
be determined. For this reasons, it is desirable for the lexical analyzer to read its input from an input
buffer.
9. What is preliminary scanning?
It is a process performed as characters are moved from the source file to the buffer. e.g. deleting
comments, deleting blanks, collapsing strings of several blanks to one blank, etc.
10. Draw neat labeled transition diagram for recognizing any valid identifier.

Letter Letter/Digit
0 1 2
Delimiter

11. What are the functions of lexical analyzer?


1. Its main task is to read the input characters and produce as output a sequence of tokens that the parser
uses for syntax analysis.
2. Stripping out from the source program comments and white space in the form of blank, tab, and
newline characters.
3. It also correlates error messages from the compiler with the source program.
4. Is responsible of making copy of the source program with the error messages.
5. If the source language supports macros then macro preprocessor functions also to be performed by the
lexical analyzer.
12. What is input buffering?
The lexical analyzer scans the characters of the source program one at a time to discover tokens. Often,
however, many characters beyond the next token may have to be examined before the next token itself can
be determined. For this reason, it is desirable for the lexical analyzer to read its input from an input buffer.
13. Lexical analyzer keeps the track of line number. State true or false.
True.
14. What is the O/P of a LEX program?
LEX program generates scanner written in C language (lex.yy.c)
15. State the use of function ‘retract()’.
It backtracks lookahead pointer and assigns it to input pointer.
16. State the use of function ‘install()’.
Adds symbol found into symbol table and returns pointer.
17. Give structure of LEX program.

©net2net 25
One Line Answers
declarations
%%
translation rules
%%
auxiliary functions
18. What is manifest constant?
Manifest constants are identifiers declared to stand for a constant, e.g., the name of a token.
19. State the pattern for regular expression ‘signed number’ in lex language notation.
[+-]?[0-9]+
20. Write the purpose of lex library functions-yylex ( )and yyerror( ).
yylex()- The lexical analyzer yylex() produces tokens consisting of a token name and its associated
attribute value.
yyerror() – Called by scanner or parser to display error encountered.
21. What are sentinels?
The sentinel is a special character that cannot be part of the source program, and a natural choice is the
character eof.
22. How conflict can be resolved in Lex
When several prefixes of the input match one or more patterns:
1. Always prefer a longer prefix to a shorter prefix.
2. If the longest possible prefix matches two or more patterns, prefer the pattern listed first in the Lex
program.
23. Explain the advantage of a lexical analyzer generator.
Advantage of lexical analyzer generator is that human efforts are reduced. Otherwise using handcoding
technique we are only suppose to construct NFA for different regular expressions, convert it to DFA,
minimize it and then convert it into code. This is happening within fraction of seconds using scanner
generator.
24. State the pattern for regular expression “set of a’s and b’s of length 2”, in lex language notation .
[ab]{2}
25. State the pattern for regular expression “any character between ‘P’ and ‘S’ irrespective of its case”,
in lex language notation.
[P-Sp-s]

Chapter 3: Parser
1. What is parser?
A parser for grammar G is a program that takes as input a string w and produces as output either a parse
tree for w, if w is a sentence of G, or an error message indicating that w is not a sentence of G.
2. What are the two functions of parser?
1. Checks whether the tokens appearing in its input, which is the output of the lexical analyzer, occurs in
patterns that are permitted by the specification for the source language (grammar).
2. Imposes a tree like structure that is used by the subsequent phases of the compiler.
3. Define handle.
While reduction we find substring in the sentential form which matches RHS of some production. Such
substring is called handle.
4. What is handle pruning?
The process of discovering a handle in the sentential form & reducing it to the appropriate left-hand side
is called handle pruning.
5. What are the demerits of SLR?
1. It will not produce uniquely defined parsing action tables for all grammars.

©net2net 26
One Line Answers
2. Shift-Reduce conflict.
6. Why LR parsing is good and attractive?
1. LR parsers can be constructed for all programming language constructs for which CFG can be
written.
2. LR parser can detect syntactic error as soon as possible, when left-to-right scan of the input.
7. How will you change the given grammar to an augmented grammar?
If ‘G’ is a grammar with start symbol ‘S’ then GWis the augmented grammar for G, such that GWis G
with a new start symbol SWand with production SW→S.
8. Explain the need of augmentation.
To indicate to the parser that, when it should stop parsing and when to announce acceptance of the input.
Acceptance occurs when the parser is about to reduce by SW→S.
9. Let I is a set of LR(O) items, and X is a grammar symbol. Define GOTO(I, X)
GOTO(I,X)={CLOSURE({AαX.β})|Aα.Xβ is in I}
10. Construct LR(O) item for A→ →∈
LR(0) item for A→∈ is A→•
11. What do LL and LR stand for?
LL – First L indicates leftmost derivation and second L indicates input scanned from left to right.
LR – Input scanned from left to right and generates rightmost derivation in reverse.
12. Construct LR(0) items for following production: A XYZ.
AXYZ yields four items
A•XYZ
AX•YZ
AXY•Z
AXYZ•
13. Explain the function CLOSURE(I).
If I is a set of items for a grammar G, then the set of items CLOSURE(I) is constructed from I by the
rules.
1. Every item in I is in CLOSURE (I)
2. If Aα.Bβ is in CLOSURE (I) and Bγ is a production, add the item B.γ to I, if it isn’t already
there.
14. Define CLOSURE(I) operation in LR parsers.
For LR(1) item I, CLOSURE (I) is constructed as follows:
1. Everything in I is in CLOSURE(I)
2. If [Aα.Bβ,a] is in I and Bγ is a production then add β.γ,b] to CLOSURE (I) for every terminal
‘b’ in FIRST(βa)
15. Which type of conflict is not possible in LR parser?
Shift-Shift conflict is not possible in LR parser.
16. Which kind of parser is most common in compilers?
LALR(Look Ahead Left Right) parser is most common in compilers.
17. Recursive decent parser is bottom up type parser. State True or False.
False
18. What is left recursive grammar?
A grammar G is said to be left-recursive if it has a non-terminal A such that there is a derivation A→Aα
for some α
19. What is left factoring?
If A→αβ|αγ are two A-productions, and the input begins with a non-empty string derived from α, we do
not know whether to expand A to αβ or αγ. Left factoring the above grammar we get following
productions:

©net2net 27
One Line Answers
A→αA’
A’→β|γ
20. Left recursive grammars are not suitable for top down parsing. State true or false.
True.
21. List actions taken by shift reduce parser.
1. Shift
2. Reduce
3. Accept
4. Error
22. Define viable prefixes.
The set of prefixes of right sentential forms that can appear on the stack of a shift reduce parser are called
viable prefixes.
23. List down the conflicts during shift-reduce parsing.
1. Shift/reduce conflict: Parser cannot decide whether to shift or reduce.
2. Reduce/reduce conflict: Parser cannot decide which of the several reductions to make.
24. Differentiate Kernel and non-Kernel items.
Kernel items include the initial item, S’.S and all items whose dots are not at the left end. Whereas the
non-kernel items have their dots at the left end.
25. What are the components of LR parser?
1. An input.
2. An output.
3. A stack.
4. A driver program.
5. A parsing table.
26. List the different techniques to construct an LR parsing table?
1. Simple LR(SLR).
2. Canonical LR.
3. Lookahead LR (LALR).
27. YACC is a parser. State true or false.
False
28. What is the syntax for YACC source specification program?
Declarations
%%
Translation rules
%%
Supporting C-routines
29. How YACC resolves parsing action conflicts?
A reduce/reduce conflict is resolved by choosing the conflicting production listed first in the YACC
specification. A shift/reduce conflict is resolved by shifting action or introduce associativity and
precedence.
30. What are the actions performed by a shift reduce parser?
1. Shift
2. Reduce
3. Accept
4. Error
31. What is a recursive descent parser?

©net2net 28
PAPER –II: THEORETICAL COMPUTER SCIENCE AND COMPILER CONSTRUCTION –II

A parser that uses a set of recursive procedures to recognize its input with no backtracking is called a
recursive-descent parser.
32. Why is the precedence and associativity required in the declaration section of a yacc program?
A shift reduce conflicts can be removed by giving precedence and associativity in the declaration section
of a yacc program?
33. What is an operator grammar?
The grammar not having ∈-production and right-side of each production is not having two adjacent non-
terminals.
e.g. SS+S|S*S|id
34. State the relation between number of states in SLR and LALR parser.
Total number of states in SLR are approximately equal to LALR parser.
35. Do left factoring in the following grammar.
AaBcC | aBb | aB | a
BW
CW
After left factoring
AaBA’|a
A’cC|b|W
BW
CW
36. What is conflict? Which type of conflict cannot occur in LR parsers?
If there are multiple entries in LR parsing table then if say conflict has occur. Reduce/reduce can never
occur in LR parsers.
37. State the meaning of ‘UMINUS’ in yacc.
UMINUS represents unary minus. If used as %prec UMINUS then it indicated give precedence of unary
minus.

Chapter 4: Syntax Directed Translation


1. What is syntax directed definition.
It is a generalization of a CFG in which each grammar symbol has an associated set of attributes like,
synthesized attribute and inherited attribute.

2. What is syntax directed translation.


A syntax-directed translation scheme embeds program fragments called semantic actions within
production bodies.

3. Compare SDD and SDT


SDD SDT
SDDs can be more readable SD translation scheme can be more efficient
More useful for specifications. More useful for implementations.
4. How the value of synthesized attribute is computed?
It is computed from the values of attributes at the children of that node in the parse tree.
5. How the value of inherited attribute is computed?

©net2net 29
PAPER –II: THEORETICAL COMPUTER SCIENCE AND COMPILER CONSTRUCTION –II

It is computed from the value of attributes at the siblings and parent of that node.
6. Define annotated parse tree.
A parse tree showing the values of attributes at each node is called an annotated parse tree.
7. What do you mean by a syntax tree?
Syntax tree is a variant of a parse tree in which each leaf represents an operand and each interior node
represents an operator.
8. When can semantic analysis be done?
Semantic analysis can be done during syntactic analysis or sometimes it is done at the final code
generation phase.
9. Mention the role of semantic analysis?
1. Semantic analysis checks the source program for semantic errors and gathers information for the
subsequent code-generation phase. It uses hierarchical structure to identify the operators and
operands of expressions and statements.
2. An important component of semantic analysis is type checking .In type checking the compiler
checks that each operator has operands that are permitted by the source language specification. In
such cases, certain programming language supports operand coercion or type coercion also.
10. What is dependency graph?
A dependency graph (DG) depicts the flow of information among the attribute instances in a particular
parse tree; an edge from one attribute instance to another means that the value of the first is needed to
compute the second.
11. What are two important classes of SDDs
1. The “S-attributed” and
2. The more general “L-attributed” SDD’s.
12. What is attribute grammar?
An SDD without side effect is sometimes called an attribute grammar. The rules in an attribute grammar
define the value of an attribute purely in terms of the values of other attributes and constants.
13. What is postfix SDT?
SDT’s with all actions at the right ends of the production bodies are called postfix SDT’s.
14. Give applications of SDT?
1. Construction syntax tree
2. Generating type

Chapter 5: Code Generation and Optimization


1. State the need of intermediate code.
1. A compiler for a different machine can be created by attaching a back end for the new machine to
an existing front end.
2. A machine-independent code optimize can be applied to the intermediate representation.
2. Define DAG
DAG is a directed acylic graph with the following labels on nodes:
1. Leaves are labeled by unique identifiers, either variable names or constants.
2. Interior nodes are labeled by an operator symbol.
3. Nodes are also given an extra set of identifiers for label.
3. What is value number for node?
In array representation of DAG we refer to nodes by giving the index of the record. This integer is called
value number for the node.
4. List the issues in code generation
1. Input to the code generator
2. Target programs

©net2net 30
PAPER –II: THEORETICAL COMPUTER SCIENCE AND COMPILER CONSTRUCTION –II

3. Memory management
4. Instruction selection
5. Register allocation
6. Evaluation order
5. Define basic block.
A basic block contains sequence of consecutive statements, which may be entered only at the beginning
and when it is entered it is executed in sequence without halt or possibility of branch.
6. Define flow graph.
Relationships between basic blocks are represented by a directed graph called flow graph.
7. What is code optimization? Explain local optimization.
• It is a program transformation technique applied on intermediate code so that made the code
produced runs faster or takes less space.
• Local optimization applied over small segments of a program consisting of a few source statements.
8. What are the rules to find “leader” in basic block?
- The first statement in a basic block is a leader.
- Any statement which is the target of a conditional or unconditional goto is a leader.
- Any statement which immediately follows a conditional goto is a leader.
9. State some application of DAG
1. eliminating local common sub-expressions
2. eliminating dead code
3. reordering statements that do not depend on one another
4. applying algebraic laws to reorder operands of three-address instructions
10. What are dominators?
We say node d of a flow graph dominates node n, written d dom n, if every path from the entry node of
the flow graph to n goes through d. Note that under this definition, every node dominates itself.
11. What is a dominator tree?
A useful way of presenting dominator information is in a tree, called the dominator tree, in which the
entry node is the root, and each node d dominates only its descendants in the tree.
12. What is the use of dominator?
Dominators are used to detect the loops in a program, during data float analysis.
13. What is the need of ‘code optimization’?
1. To eliminate redundancies in program.
2. Computations in a program are rearranged or rewritten so to execution efficiency is improved,
which results in faster running machine code.
14. List different code optimization techniques.
1. Compile time evaluation
2. Common sub-expression elimination
3. Frequency reduction
4. Dead code elimination
5. Strength reduction.
15. What do you mean by ‘loop invariant’ computation?
This transformation takes on expression that yields the same result independent of the number of times a
loop is executed and places the expression before the loop.
16. What is ‘strength reduction’?
The strength reduction optimization replaces the occurrence of a time consuming operation by an
occurrence of a faster operation.
e.g. X = Y*2; can be replace as X = Y + Y;

©net2net 31
PAPER –II: THEORETICAL COMPUTER SCIENCE AND COMPILER CONSTRUCTION –II

17. Name some forms of intermediate code


1. Postfix notation or polish notation.
2. Syntax tree
3. Three address code (Quadruple, Triple and Indirect Triple)
18. Write the syntax for three-address code statement, and mention its properties.
Syntax: A= B op C
Three-address instruction has at most one operator in addition to the assignment symbol. The compiler
has to decide the order in which operations are to be done. The compiler must generate a temporary
name to hold the value computed by each instruction. Some three-address instructions can have less than
three operands.
19. State the advantages of ‘intermediate code’.
1. Retargeting – build a compiler for new machine quickly.
2. Optimization – reuse intermediate code optimizers in compilers for different languages and different
machines.
20. What is meant by constant folding?
Constant folding is the process of replacing expressions by their value if the value can be computed at
compile time.
21. List the criteria for selecting a good code optimization technique.
1. It should capture most of the potential improvement without an unreasonable amount of effort.
2. It should preserve the meaning of the program
3. It should reduce the time or space taken by the object program.
22. Define code generation.
The code generation is the final phase of the compiler. It takes an intermediate representation of the
source program as the input and produces an equivalent target program as the output.
23. Give an example of 3-address code statement.
A/B*C
T1 := A/B
T2 := T1*C
T1 and T2 are names of temporary variables.
24. What are the different types of three address statements?
1. Assignment statements of the form x=y op z.
2. Assignment statements of the form x= op y.
3. Copy statements of the form x=y.
4. An unconditional jump, goto L.
5. Conditional jumps, if x relop y goto L.
6. Indexed assignments of the form, x=y[i] , x[i]=y.

Compare SLR, LR and LALR parsers


No. SLR(1) LR(1) LALR(1)
1. Set of canonical collection of Set of LR(1) items are Set of LR(1) items are
LR(0) items are generated. generated. generated.
2. Number of items of SLR are less Number of items generated LALR(1) is a merger of LR(1).
than LR(1) but approximately are more than SLR(1) and Therefore number of items are
equal to LALR(1) LALR(1) less than LR(1)
3. To construct parsing table To construct parsing table To construct parsing table
FOLLOW function is used. FIRST function is used. FIRST function is used.

©net2net 32
PAPER –II: THEORETICAL COMPUTER SCIENCE AND COMPILER CONSTRUCTION –II

4. Shift-Reduce conflict can occur in Rarely shift-reduce conflict Reduce-reduce conflict can
SLR can occur. occur in LALR
5. Good method Better method Most powerful (best) method.
6. Memory requirement is less. Memory requirement is Memory requirement is less.
large.

Compare RDP and predictive parsers


No. RDP Predictive Parser
1. Uses recursive procedures for parsing Uses predictive parsing table for parsing
2. It is recursive form of top-down parser It is non-recursive form of top-down parser.
3. Requires more memory since it is recursive Requires less memory since it is non-recursive
4. Error is indicated by calling error handling Error is indicated with the help of parsing table.
function
5. FIRST and FOLLOW functions are not FIRST and FOLLOW functions are required.
required.
6. Can be implemented only in languages those Can be implemented in all languages those have
supports recursion. array data structure.

Compare top-down and bottom-up parsing


No. Top-down parsing Bottom-up parsing
1. Uses derivation Uses reduction
2. Starts building parse tree from root and proceeds Starts building parse tree from leafs and
towards leafs proceeds towards root.
3. Left-recursion and backtracking are problems No left-recursion and backtracking problems
occurring in this parsing
4. Ambiguous grammars are not suitable for top-down It accepts ambiguous grammars
parsing
5. Top-down parsers are: Bottom-up parsers are:
1. Recursive descent parser 1. Operator precedence parser.
2. Predictive parser 2. LR parsers (SLR, CLR, LALR)
6 Precise error indication is not possible Precise indication is possible.

©net2net 33

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy