0% found this document useful (0 votes)
73 views80 pages

Cpos MCQ Bank

This document contains a 554 question multiple choice quiz on concepts of programming and operating systems. The questions are divided into sections on Java development concepts, variables and methods, data types, static variables and methods, and final variables. The questions cover topics such as the Java Runtime Environment (JRE), the Java Development Kit (JDK), the Java Virtual Machine (JVM), primitive data types, static and instance variables, and the use of the final keyword with variables.

Uploaded by

Ramkishan Shinde
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)
73 views80 pages

Cpos MCQ Bank

This document contains a 554 question multiple choice quiz on concepts of programming and operating systems. The questions are divided into sections on Java development concepts, variables and methods, data types, static variables and methods, and final variables. The questions cover topics such as the Java Runtime Environment (JRE), the Java Development Kit (JDK), the Java Virtual Machine (JVM), primitive data types, static and instance variables, and the use of the final keyword with variables.

Uploaded by

Ramkishan Shinde
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/ 80

CONCEPTS OF PROGRAMMING & OPERATING SYSTEM MCQ BANK

Total No. Of MCQs : 554


Name : Shubham Shivaji Patil

Concept Of Programming

1. Lecture: Getting Started


1. What does JRE stand for in the context of Java development?
a) Java Runtime Execution
b) Java Runtime Environment
c) Java Runtime Extension
d) Java Runtime Engine
Answer: b) Java Runtime Environment

2. Which component is responsible for compiling Java source code into bytecode?
a) JDK (Java Development Kit)
b) JRE (Java Runtime Environment)
c) JVM (Java Virtual Machine)
d) Eclipse IDE (Integrated Development Environment)
Answer: a) JDK (Java Development Kit)

3. What is the primary purpose of the Java Virtual Machine (JVM)?


a) To execute Java bytecode directly on the processor
b) To convert Java source code to machine code
c) To manage memory allocation and garbage collection
d) To provide a development environment for Java programs
Answer: a) To execute Java bytecode directly on the processor

4. Which component of the Java development environment is required to run Java applications on your
system?
a) JDK (Java Development Kit)
b) JRE (Java Runtime Environment)
c) JVM (Java Virtual Machine)
d) Eclipse IDE (Integrated Development Environment)
Answer: b) JRE (Java Runtime Environment)

5. What is the purpose of the Eclipse IDE in Java development?


a) To execute Java programs and manage runtime environments
b) To provide a code editor, debugger, and other development tools
c) To compile Java source code into bytecode
d) To manage memory allocation and garbage collection
Answer: b) To provide a code editor, debugger, and other development tools

6. Which Java development component contains the tools necessary for Java application development,
including the compiler?
a) JRE (Java Runtime Environment)
b) JVM (Java Virtual Machine)
c) JDK (Java Development Kit)
d) Eclipse IDE (Integrated Development Environment)
Answer: c) JDK (Java Development Kit)

7. What is the purpose of setting up the Java development environment?


a) To install Java games and applications on your computer
b) To create and run Java programs on your computer
c) To browse websites written in Java programming language
d) To optimize the performance of your computer
Answer: b) To create and run Java programs on your computer

8. Which component of the Java development environment is responsible for interpreting and
executing Java bytecode?
a) JRE (Java Runtime Environment)
b) JVM (Java Virtual Machine)
c) JDK (Java Development Kit)
d) Eclipse IDE (Integrated Development Environment)
Answer: b) JVM (Java Virtual Machine)

9. What is the minimum requirement for setting up the Java development environment?
a) JRE (Java Runtime Environment)
b) JDK (Java Development Kit)
c) JVM (Java Virtual Machine)
d) Eclipse IDE (Integrated Development Environment)
Answer: b) JDK (Java Development Kit)

10. Which component of the Java development environment provides a graphical user interface for
Java programming?
a) JRE (Java Runtime Environment)
b) JDK (Java Development Kit)
c) JVM (Java Virtual Machine)
d) Eclipse IDE (Integrated Development Environment)
Answer: d) Eclipse IDE (Integrated Development Environment)

2. Variables & Methods


**1. About main() method**

1. What is the significance of the `main()` method in a Java program?


a) It is the entry point of the program where the execution starts.
b) It is used to declare variables for the entire program.
c) It is responsible for declaring methods in Java.
d) It is used to define the class properties.
Answer: a) It is the entry point of the program where the execution starts.

2. Which access modifier is commonly used for the `main()` method in Java?
a) public
b) private
c) protected
d) static
Answer: public

3. What is the return type of the `main()` method?


a) void
b) int
c) String
d) double
Answer: b) int

4. Can a Java program have multiple `main()` methods?


a) Yes, as long as they have different return types.
b) No, a Java program can have only one `main()` method.
c) Yes, but only if they are declared in different classes.
d) Yes, but only if they have different access modifiers.
Answer: b) No, a Java program can have only one `main()` method.

5. Which keyword is used to declare the `main()` method in Java?


a) function
b) start
c) main
d) public
Answer: c) main

**2. Java Data Types, Primitives, and Binary Literals**

1. Which of the following is NOT a primitive data type in Java?


a) int
b) double
c) String
d) char
Answer: c) String

2. How many bytes does the `double` data type occupy in memory in Java?
a) 4 bytes
b) 8 bytes
c) 16 bytes
d) It varies depending on the platform.
Answer: b) 8 bytes

3. Which primitive data type is used to store characters in Java?


a) char
b) int
c) byte
d) short
Answer: a) char

4. What is the default value of the `int` data type in Java if it is not explicitly initialized?
a) 0
b) 0.0
c) null
d) It does not have a default value.
Answer: a) 0

5. How do you represent a binary literal in Java?


a) Starting with 0b, followed by binary digits
b) Starting with 0x, followed by hexadecimal digits
c) Starting with 0, followed by octal digits
d) Binary literals are not supported in Java.
Answer: a) Starting with 0b, followed by binary digits

**3. Data Type Compatibility and Casting of Primitive Data Types**

1. What is data type compatibility in Java?


a) The ability to convert objects of one class to objects of another class.
b) The ability to assign values of one data type to variables of another data type.
c) The ability to compare variables of different data types.
d) The ability to convert primitive data types to objects.
Answer: b) The ability to assign values of one data type to variables of another data type.

2. What is the result of the following expression: `int a = 10; double b = 3.5; double c = a + b;` ?
a) 13
b) 13.0
c) Compilation error
d) Runtime exception
Answer: b) 13.0
3. What is the process of converting a data type of higher range to a data type of lower range called in
Java?
a) Upcasting
b) Downcasting
c) Typecasting
d) Narrowing
Answer: d) Narrowing

4. What is the correct way to cast a double variable `d` to an int in Java?
a) int result = (int)d;
b) int result = int(d);
c) int result = convertToInt(d);
d) int result = int(d);
Answer: a) int result = (int)d;

5. What happens if you try to cast a value that is too large for the target data type?
a) The value is automatically rounded to the nearest integer.
b) The compiler will automatically perform the necessary conversion.
c) The value will be truncated, and the result may be incorrect.
d) Java does not allow casting of values that are too large.
Answer: c) The value will be truncated, and the result may be incorrect.

**4. Static Variables and Methods**

1. What is a static variable in Java?


a) A variable that cannot be modified.
b) A variable that is shared among all instances of the class.
c) A variable that can only be accessed within the same method.
d) A variable that is declared inside a static block.
Answer: b) A variable that is shared among all instances of the class.

2. How do you access a static variable in Java?


a) By using the `this` keyword
b) By creating an object of the class
c) By using the class name followed by the dot operator
d) By using the `super` keyword
Answer: c) By using the class name followed by the dot operator

3. Which keyword is used to define a static method in Java?


a) static
b) public
c) void
d) static void
Answer: a) static

4. Can a static method access instance variables of the class?


a) Yes
b) No
c) Only if the instance variables are also static
d) Only if the method is declared as public
Answer: b) No

5. What is the purpose of using static methods in Java?


a) To perform operations that do not require an object of the class
b) To access instance variables of the class
c) To prevent the modification of variables
d) To declare constants in the class
Answer: a) To perform operations that do not require an object of the class
**5. Accessing Static Variables and Methods of Different Class**

1. Can a static method in one class access a static variable in another class directly?
a) Yes
b) No
c) Only if both classes are in the same package
d) Only if the method is declared as private
Answer: a) Yes

2. How do you access a static method of a different class in Java?


a) By creating an object of the class
b) By using the `this` keyword
c) By using the class name followed by the dot operator
d) By using the `super` keyword
Answer: c) By using the class name followed by the dot operator

3. Which of the following is true about static variables?


a) They are specific to an instance of the class.
b) They are initialized only when an object is created.
c) They are shared among all instances of the class.
d) They cannot be accessed from static methods.
Answer: c) They are shared among all instances of the class.

4. In Java, can you use an instance variable to initialize a static variable?


a) Yes
b) No
c) Only if the instance variable is marked as public
d) Only if the instance variable is marked as static
Answer: b) No

5. How do you access a static variable of a different class in Java?


a) By creating an object of the class
b) By using the `this` keyword
c) By using the class name followed by the dot operator
d) By using the `super` keyword
Answer: c) By using the class name followed by the dot operator

**6. Final Variables**

1. What does the `final` keyword signify when used with variables in Java?
a) The variable cannot be modified once it is assigned a value.
b) The variable cannot be accessed from outside the class.
c) The variable cannot be declared in any other class.
d) The variable cannot be declared inside a static method.
Answer: a) The variable cannot be modified once it is assigned a value.

2. Can a `final` variable be initialized at a later stage after declaration?


a) Yes
b) No
c) Only if the variable is marked as static
d) Only if the variable is marked as private
Answer: b) No

3. How is a `final` variable different from a constant?


a) A `final` variable can be modified, but a constant cannot.
b) A `final` variable can be declared anywhere in the code, but a constant cannot.
c) A `final` variable is associated with a specific instance, but a constant is not.
d) A `final` variable is associated with a specific class, but a constant is not.
Answer: a) A `final` variable can be modified, but a constant cannot.

4. In Java, can a `final` variable have different values for different instances of the same class?
a) Yes
b) No
c) Only if the variable is marked as private
d) Only if the variable is marked as static
Answer: a) Yes

5. What is the main advantage of using `final` variables in Java?


a) They improve performance and memory utilization.
b) They prevent accidental changes to the variable's value.
c) They allow the variable to be accessed from any class.
d) They automatically initialize the variable to a default value.
Answer: b) They prevent accidental changes to the variable's value.

3. Operators
**1. Arithmetic Operator**

1. What is the arithmetic operator used for addition in Java?


a) +
b) -
c) *
d) /
Answer: a) +

2. Which arithmetic operator is used for division in Java, resulting in an integer quotient?
a) /
b) %
c) *
d) //
Answer: a) /

3. What is the result of the expression `5 + 3 * 2` in Java?


a) 16
b) 11
c) 13
d) 15
Answer: c) 13

4. Which arithmetic operator is used for exponentiation in Java?


a) ^
b) **
c) ^
d) **
Answer: There is no exponentiation operator in Java.

5. What is the value of the expression `10 % 3` in Java?


a) 3
b) 0
c) 1
d) 2
Answer: c) 1

**2. Relational Operator**

1. Which relational operator checks if two values are equal in Java?


a) =
b) ==
c) !=
d) <=
Answer: b) ==

2. What is the result of the expression `5 > 3` in Java?


a) true
b) false
Answer: a) true

3. What does the relational operator `!=` signify in Java?


a) Not equal to
b) Less than or equal to
c) Greater than or equal to
d) Assignment
Answer: a) Not equal to

4. Which relational operator checks if one value is greater than another in Java?
a) >
b) <
c) >=
d) <=
Answer: a) >

5. What is the result of the expression `10 <= 5` in Java?


a) true
b) false
Answer: b) false

**3. Logical Operator**

1. Which logical operator represents the logical AND in Java?


a) &
b) &&
c) |
d) ||
Answer: b) &&

2. What is the result of the expression `true && false` in Java?


a) true
b) false
Answer: b) false

3. What does short-circuit evaluation mean for logical operators in Java?


a) All conditions are evaluated before proceeding with the logical operation.
b) The logical operation stops as soon as the first true condition is encountered.
c) The logical operation stops as soon as the first false condition is encountered.
d) Logical operators do not support short-circuit evaluation in Java.
Answer: b) The logical operation stops as soon as the first true condition is encountered.

4. Which logical operator represents the logical OR in Java?


a) &
b) &&
c) |
d) ||
Answer: d) ||

5. What is the result of the expression `false || true` in Java?


a) true
b) false
Answer: a) true

**4. Unary Operator**

1. What is the unary operator for incrementing a variable by 1 in Java?


a) ++
b) +
c) --
d) -
Answer: a) ++

2. What is the result of the expression `++5` in Java?


a) 5
b) 6
c) 7
d) 4
Answer: b) 6

3. What is the unary operator for decrementing a variable by 1 in Java?


a) ++
b) +
c) --
d) -
Answer: c) --

4. What is the result of the expression `--5` in Java?


a) 5
b) 6
c) 4
d) 3
Answer: c) 4

5. How many operands does a unary operator take in Java?


a) One
b) Two
c) Three
d) It varies depending on the operator.
Answer: a) One

**5. Ternary Operator**

1. What is the syntax of the ternary operator in Java?


a) a ? b : c
b) a : b ? c
c) a ? b ? c
d) a ? b ? : c
Answer: a) a ? b : c

2. What is the result of the expression `5 > 3 ? "Yes" : "No"` in Java?


a) true
b) false
c) Yes
d) No
Answer: c) Yes

3. Can the ternary operator be used as a replacement for if-else statements in Java?
a) Yes, in all cases
b) No, the ternary operator can only be used with boolean expressions
c) No, the ternary operator can only be used with integer expressions
d) Yes, but only for simple conditions
Answer: a) Yes, in all cases

4. What does the ternary operator evaluate in Java?


a) Two expressions
b) Three expressions
c) One expression
d) It varies depending on the operator.
Answer: c) One expression

5. What is the result of the expression `true ? 1 : 0` in Java?


a) 1
b) 0
Answer: a) 1

**6. Assignment Operator**

1. Which symbol represents the assignment operator in Java?


a) =
b) ==
c) ===
d) :=
Answer: a) =

2. What is the purpose of the assignment operator in Java?


a) To perform addition of two variables.
b) To compare two values for equality.
c) To assign a value to a variable.
d) To perform logical AND operation.
Answer: c) To assign a value to a variable.

3. What is the result of the expression `int x = 5;` in Java?


a) x is declared but not initialized.
b) x is assigned the value 5.
c) x is compared to 5 for equality.
d) x is assigned the value of another variable.
Answer: b) x is assigned the value 5.

4. Can the assignment operator be used to assign values to multiple variables simultaneously in Java?
a) Yes, using commas to separate the variables.
b) Yes, using semicolons to separate the variables.
c) No, the assignment operator can only assign a value to one variable at a time.
d) No, multiple assignments are not allowed in Java.
Answer: a) Yes, using commas to separate the variables.

5. What is the result of the expression `x = y = 10;` in Java, assuming both x and y are integer variables?
a) x and y are assigned the value 10.
b) x and y are compared for equality.
c) Compilation error due to incorrect syntax.
d) The expression is invalid and will throw a runtime error.
Answer: a) x and y are assigned the value 10.

4. Lecture: Conditional and Looping Statements


**1. If, else if, switch**

1. In Java, what is the purpose of the "if" statement?


a) To define a block of code that will be executed repeatedly.
b) To check if a condition is true and execute a block of code if it is.
c) To terminate the program immediately.
d) To define a method with a specific name.
Answer: b) To check if a condition is true and execute a block of code if it is.

2. What is the difference between "if" and "else if" statements in Java?
a) "else if" can only be used after an "if" statement.
b) "if" can only be used after an "else if" statement.
c) "else if" can be used independently without an "if" statement.
d) There is no difference; they are the same in functionality.
Answer: c) "else if" can be used independently without an "if" statement.

3. Which keyword is used to exit a switch statement in Java?


a) stop
b) exit
c) break
d) continue
Answer: c) break

4. What happens if there is no "break" statement in a case block of a switch statement?


a) The program throws a compile-time error.
b) The program executes the code in that case block and continues to the next case.
c) The program ignores the entire switch statement.
d) The program enters an infinite loop.
Answer: b) The program executes the code in that case block and continues to the next case.

5. How can you handle multiple conditions in a switch statement?


a) Using nested switch statements
b) Using "if" statements inside the switch cases
c) Using "else if" statements after the switch
d) Using multiple case labels for a single block of code
Answer: d) Using multiple case labels for a single block of code

**2. break & continue keyword**

1. What does the "break" keyword do in Java?


a) It terminates the execution of the entire program.
b) It skips the current iteration of a loop and continues with the next iteration.
c) It is used to declare the end of a method.
d) It transfers control to the catch block in exception handling.
Answer: b) It skips the current iteration of a loop and continues with the next iteration.

2. In Java, where can the "break" statement be used?


a) Only inside "if" statements
b) Only inside "for" loops
c) Only inside "switch" statements
d) Inside "for" loops, "while" loops, and "switch" statements
Answer: d) Inside "for" loops, "while" loops, and "switch" statements

3. What is the purpose of the "continue" keyword in Java?


a) To stop the execution of the loop and exit immediately.
b) To skip the remaining code in the current iteration and move to the next iteration.
c) To jump to a specific label within the loop.
d) To force the loop to restart from the beginning.
Answer: b) To skip the remaining code in the current iteration and move to the next iteration.

4. In Java, where can the "continue" statement be used?


a) Only inside "if" statements
b) Only inside "for" loops
c) Only inside "switch" statements
d) Inside "for" loops, "while" loops, and "do-while" loops
Answer: d) Inside "for" loops, "while" loops, and "do-while" loops

5. What is the difference between "break" and "continue" in Java?


a) "break" terminates the loop, while "continue" skips to the next iteration.
b) "break" and "continue" are interchangeable and can be used interchangeably in loops.
c) "break" is used with "for" loops, while "continue" is used with "while" loops.
d) "break" is used to exit switch statements, while "continue" is used to exit loops.
Answer: a) "break" terminates the loop, while "continue" skips to the next iteration.

**3. for loop**

1. In a "for" loop, where is the initialization of the loop variable usually performed?
a) Before the loop starts
b) At the end of the loop
c) At the middle of the loop
d) It can be done anywhere inside the loop.
Answer: a) Before the loop starts

2. What is the purpose of the "for" loop in Java?


a) To execute a block of code repeatedly until a condition is true.
b) To check a single condition and execute a block of code based on the result.
c) To iterate over a collection of elements, such as an array.
d) To create a recursive loop in Java.
Answer: c) To iterate over a collection of elements, such as an array.

3. How many expressions can be used in the initialization part of a "for" loop?
a) One
b) Two
c) Three
d) It varies depending on the loop requirement.
Answer: c) Three

4. What does the "for" loop's condition control?


a) The number of iterations the loop will execute
b) The data type of the loop variable
c) The exit condition for the entire program
d) The order of the loop variables
Answer: a) The number of iterations the loop will execute

5. How can you exit a "for" loop prematurely before its natural termination?
a) Using the "break" statement
b) Using the "continue" statement
c) Using the "exit" keyword
d) It is not possible to exit a "for" loop prematurely.
Answer: a) Using the "break" statement

**4. while loop**

1. In Java, what is the purpose of the "while" loop?


a) To execute a block of code repeatedly until a condition is true.
b) To check a single condition and execute a block of code based on the result.
c) To iterate over a collection of elements, such as an array.
d) To create a recursive loop in Java.
Answer: a) To execute a block of code repeatedly until a condition is true.

2. Where should the update statement be placed in a "while" loop?


a) At the beginning of the loop
b) At the end of the loop
c) After the loop body
d) It is not required in a "while" loop.
Answer: c) After the loop body

3. What is the difference between the "while" loop and the "for" loop in Java?
a) The "while" loop requires an initialization statement.
b) The "while" loop allows only

one loop variable.


c) The "while" loop does not have an update statement.
d) The "while" loop can only be used for numeric iterations.
Answer: c) The "while" loop does not have an update statement.

4. How do you prevent an infinite loop from running indefinitely in Java?


a) By using the "break" statement inside the loop body
b) By using the "continue" statement inside the loop body
c) By ensuring that the loop condition eventually becomes false
d) By using the "exit" keyword
Answer: c) By ensuring that the loop condition eventually becomes false

5. In a "while" loop, when is the loop condition evaluated?


a) Before each iteration of the loop
b) After each iteration of the loop
c) Only at the start of the loop
d) Only at the end of the loop
Answer: a) Before each iteration of the loop

**5. do while loop**

1. What is the main difference between a "do-while" loop and a "while" loop in Java?
a) The "do-while" loop has a loop variable, while the "while" loop does not.
b) The "do-while" loop executes the loop body at least once, while the "while" loop may not execute
at all.
c) The "do-while" loop does not support a loop condition, while the "while" loop does.
d) The "do-while" loop does not allow an update statement, while the "while" loop does.
Answer: b) The "do-while" loop executes the loop body at least once, while the "while" loop may not
execute at all.

2. In Java, where should the update statement be placed in a "do-while" loop?


a) Before the "do" keyword
b) After the "do" keyword and before the "while" keyword
c) After the "while" keyword
d) Before the loop body
Answer: b) After the "do" keyword and before the "while" keyword

3. What is the syntax of a "do-while" loop in Java?


a) while (condition) { ... }
b) do { ... } while (condition);
c) do while (condition) { ... }
d) do { ... } until (condition);
Answer: b) do { ... } while (condition);

4. How many times will a "do-while" loop execute its loop body if the loop condition is initially false?
a) Zero times
b) One time
c) Infinitely
d) It depends on the update statement.
Answer: a) Zero times
5. What is the advantage of using a "do-while" loop over a "while" loop in Java?
a) "do-while" loops are more efficient in terms of execution speed.
b) "do-while" loops are easier to read and understand.
c) "do-while" loops always execute the loop body at least once.
d) "do-while" loops support multiple loop variables.
Answer: c) "do-while" loops always execute the loop body at least once.

**6. Recursion**

1. What is recursion in Java?


a) A way to define a variable multiple times within a method.
b) A method calling itself to solve a problem.
c) A loop that iterates over an array.
d) A way to break out of nested loops.
Answer: b) A method calling itself to solve a problem.

2. What is the base case in recursive methods?


a) The first case of the recursion
b) The condition that causes the recursion to stop
c) The final return statement in the method
d) The largest value used in the recursion
Answer: b) The condition that causes the recursion to stop

3. What is the advantage of using recursion over iterative approaches in some cases?
a) Recursion always results in faster execution.
b) Recursion uses less memory compared to iterative approaches.
c) Recursion is easier to implement and debug.
d) Recursion can lead to simpler and cleaner code for certain problems.
Answer: d) Recursion can lead to simpler and cleaner code for certain problems.

4. In Java, can a recursive method call other methods within its body?
a) Yes, but only if the other methods are also recursive.
b) Yes, recursive methods can call any other methods.
c) No, recursive methods cannot call any other methods.
d) Only if the other methods are declared as static.
Answer: b) Yes, recursive methods can call any other methods.

5. What is the potential risk of using recursion in Java?


a) It may lead to stack overflow errors for large inputs.
b) Recursion is always slower than iteration.
c) Recursive methods cannot return values.
d) Recursive methods can only be used with certain data types.
Answer: a) It may lead to stack overflow errors for large inputs.

5. Lecture: Objects
**1. Reference variables and methods**

1. In Java, what is a reference variable?


a) A variable that stores the memory address of another variable.
b) A variable that stores the value of an integer.
c) A variable that can only be used with primitive data types.
d) A variable that stores the result of a mathematical operation.
Answer: a) A variable that stores the memory address of another variable.

2. How are reference variables used with objects in Java?


a) They store the actual data of the object.
b) They store the name of the object's class.
c) They allow access to the methods and data members of the object.
d) They are used for arithmetic operations on objects.
Answer: c) They allow access to the methods and data members of the object.

3. What happens if a reference variable is not initialized in Java?


a) It will cause a compile-time error.
b) It will be assigned a default value of zero.
c) It will be assigned a default value of null.
d) It will cause a runtime error.
Answer: c) It will be assigned a default value of null.

4. How do you call a method using a reference variable in Java?


a) referenceVariable.methodName();
b) methodName.referenceVariable();
c) method(referenceVariable);
d) referenceVariable = methodName();
Answer: a) referenceVariable.methodName();

5. Can you change the object referenced by a reference variable in Java?


a) No, once assigned, the reference variable always points to the same object.
b) Yes, by using the "set" method provided by the Java API.
c) Yes, by directly assigning a new object to the reference variable.
d) No, it is not possible to use reference variables with objects.
Answer: c) Yes, by directly assigning a new object to the reference variable.

**2. Constructors (Default constructor, parameterized constructor)**

1. What is a constructor in Java?


a) A method used to convert one data type to another.
b) A special method used to create and initialize objects of a class.
c) A method used to perform arithmetic operations on objects.
d) A method used to compare objects for equality.
Answer: b) A special method used to create and initialize objects of a class.

2. What is the purpose of a default constructor in Java?


a) To create objects without any initialization.
b) To create objects with default values for all data members.
c) To create objects without any parameters passed.
d) To create objects without any memory allocation.
Answer: c) To create objects without any parameters passed.

3. How is a default constructor different from a parameterized constructor in Java?


a) A default constructor has parameters, while a parameterized constructor does not.
b) A default constructor is automatically provided by Java, while a parameterized constructor is user-
defined.
c) A default constructor does not have a body, while a parameterized constructor has a body.
d) A default constructor can be overloaded, while a parameterized constructor cannot.
Answer: b) A default constructor is automatically provided by Java, while a parameterized
constructor is user-defined.

4. When is the default constructor called in Java?


a) Only when an object is created using the "new" keyword.
b) Only when an object is passed as an argument to a method.
c) Whenever an object is created, if there is no other constructor defined.
d) Whenever an object is created, regardless of the constructor defined.
Answer: c) Whenever an object is created, if there is no other constructor defined.

5. How can you define multiple constructors in a Java class?


a) By providing different return types for each constructor.
b) By using the "constructor" keyword before each constructor definition.
c) By changing the access modifiers of each constructor.
d) By using different parameter lists for each constructor.
Answer: d) By using different parameter lists for each constructor.

**3. Static method v/s instance method**

1. What is a static method in Java?


a) A method that can only be called on objects of the class.
b) A method that can be called directly on the class without creating an object.
c) A method that is used to perform arithmetic operations on objects.
d) A method that is defined as "private" within the class.
Answer: b) A method that can be called directly on the class without creating an object.

2. How can you call a static method in Java?


a) By using a reference variable of the class.
b) By creating an object of the class.
c) By using the "this" keyword within the method.
d) By using the class name followed by the method name.
Answer: d) By using the class name followed by the method name.

3. What is the main difference between a static method and an instance method in Java?
a) A static method cannot access instance variables, while an instance method can.
b) A static method cannot be overridden, while an instance method can.
c) A static method can only be called on objects, while an instance method can be called on the class
directly.
d) There is no difference; they can be used interchangeably.
Answer: a) A static method cannot access instance variables, while an instance method can.

4. When should you use a static method in Java?


a) When the method requires access to instance variables.
b) When the method should be called on objects of the class.
c) When the method does not depend on the state of an object.
d) When the method needs to be overridden by subclasses.
Answer: c) When the method does not depend on the state of an object.

5. Can a static method access instance variables directly in Java?


a) Yes, a static method can access instance variables directly.
b) No, a static method can only access static variables.
c) Yes, but only if the instance variables are declared as "final".
d) No, a static method cannot access any variables.
Answer: b) No, a static method can only access static variables.

**4. Reference variable as an instance member of the class**

1. In Java, can a class have a reference variable as an instance member?


a) No, reference variables can only be used inside methods.
b) Yes, a reference variable can be declared as an instance member of a class.
c) Yes, but only if the reference variable is marked as "static".
d) No, reference variables are used to store memory addresses, not as instance members.
Answer: b) Yes, a reference variable can be declared as an instance member of a class.

2. How can you access an instance member reference variable in Java?


a) By creating an object of the class and calling the variable using the object.
b) By using the "new" keyword to create the variable.
c) By accessing it directly without using any object.
d) By using the "this" keyword within the class.
Answer: a) By creating an object of the class and calling the variable
using the object.

3. What is the scope of an instance member reference variable in Java?


a) It can be accessed anywhere within the class.
b) It can be accessed only inside the method where it is declared.
c) It can be accessed anywhere within the package.
d) It can be accessed globally in any part of the program.
Answer: a) It can be accessed anywhere within the class.

4. Can multiple objects of the same class have different values for an instance member reference
variable?
a) Yes, the value of an instance member reference variable is unique for each object.
b) No, all objects of the same class share the same value for an instance member reference variable.
c) Yes, but only if the variable is declared as "final".
d) No, instance member reference variables cannot have different values for different objects.
Answer: a) Yes, the value of an instance member reference variable is unique for each object.

5. How is an instance member reference variable different from a static variable in Java?
a) An instance member reference variable can only be accessed using the class name.
b) An instance member reference variable can be accessed globally without creating an object.
c) An instance member reference variable is unique for each object, while a static variable is shared
among all objects of the class.
d) An instance member reference variable cannot be used as a method argument.
Answer: c) An instance member reference variable is unique for each object, while a static variable is
shared among all objects of the class.

**5. String class**

1. In Java, what is the purpose of the String class?


a) To perform arithmetic operations on strings.
b) To represent sequences of characters as a data type.
c) To create and initialize objects of a class.
d) To convert string literals to numeric values.
Answer: b) To represent sequences of characters as a data type.

2. How do you create a new String object in Java?


a) Using the "new" keyword followed by the string literal.
b) By directly assigning a value to a String variable.
c) By using the "create" method of the String class.
d) By using the "stringOf" method of the String class.
Answer: a) Using the "new" keyword followed by the string literal.

3. In Java, are String objects mutable or immutable?


a) String objects are mutable and can be changed after creation.
b) String objects are immutable and cannot be changed after creation.
c) String objects are partially mutable; only certain characters can be changed.
d) String objects are mutable, but only if the "final" keyword is used in the declaration.
Answer: b) String objects are immutable and cannot be changed after creation.

4. What happens when you concatenate two String objects in Java using the "+" operator?
a) The two objects are added together as numbers.
b) A compile-time error occurs.
c) The two objects are joined to form a new String object.
d) The two objects are compared for equality.
Answer: c) The two objects are joined to form a new String object.

5. What is the purpose of the "length" method of the String class in Java?
a) To get the number of characters in the string.
b) To get the number of words in the string.
c) To get the memory address of the string.
d) To get the maximum size of the string.
Answer: a) To get the number of characters in the string.

6. Lecture: Arrays
**1. Initializing an Array in Java**

1. Which of the following is the correct way to initialize an array in Java?


a) int[] arr = {1, 2, 3, 4, 5};
b) int arr[5] = {1, 2, 3, 4, 5};
c) int arr[] = new int[]{1, 2, 3, 4, 5};
d) int arr = new int[5]{1, 2, 3, 4, 5};
Answer: c) int arr[] = new int[]{1, 2, 3, 4, 5};

2. What happens if you try to access an array element that is out of bounds in Java?
a) The program will throw a compile-time error.
b) The program will throw a runtime exception (ArrayIndexOutOfBoundsException).
c) The program will silently ignore the incorrect access.
d) The program will automatically resize the array to accommodate the access.
Answer: b) The program will throw a runtime exception (ArrayIndexOutOfBoundsException).

3. In Java, can you change the size of an array after it is initialized?


a) Yes, you can change the size of an array by re-declaring it with a new size.
b) No, the size of an array is fixed and cannot be changed once initialized.
c) Yes, you can use the "resize" method to change the size of an array.
d) No, you can only change the elements of an array, not its size.
Answer: b) No, the size of an array is fixed and cannot be changed once initialized.

4. What is the default initial value for elements in an integer array in Java?
a) 0
b) 1
c) -1
d) null
Answer: a) 0

5. Can you initialize an array without specifying its size in Java?


a) No, you must always specify the size of the array during initialization.
b) Yes, Java automatically determines the size based on the number of elements provided.
c) Yes, but only for certain data types like strings and characters.
d) No, arrays must be initialized with a fixed size.
Answer: b) Yes, Java automatically determines the size based on the number of elements provided.

**2. Two-dimensional array in Java**

1. How do you declare a two-dimensional array in Java?


a) int[][] arr = new int[3][3];
b) int[3][3] arr = new int[][];
c) int[3, 3] arr = new int[];
d) int[3][3] arr = new int[3][3];
Answer: a) int[][] arr = new int[3][3];

2. What is the syntax to access an element in a two-dimensional array in Java?


a) arr[row][column]
b) arr[row, column]
c) arr(row, column)
d) arr[row][row]
Answer: a) arr[row][column]
3. How do you initialize a two-dimensional array with specific values in Java?
a) int[][] arr = new int[3][3]{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
b) int[][] arr = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
c) int[][] arr = new int[3][3](1, 2, 3, 4, 5, 6, 7, 8, 9);
d) int[3][3] arr = new int[][];
Answer: b) int[][] arr = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};

4. What is the number of rows and columns in the following two-dimensional array declaration?
int[][] arr = new int[4][2];
a) 2 rows, 4 columns
b) 4 rows, 2 columns
c) 4 rows, 4 columns
d) 2 rows, 2 columns
Answer: b) 4 rows, 2 columns

5. Can the rows in a two-dimensional array have different lengths in Java?


a) No, all rows must have the same length in a two-dimensional array.
b) Yes, each row can have a different length in a two-dimensional array.
c) Yes, but only if the array is declared as "dynamic."
d) No, the size of the rows must be specified during array initialization.
Answer: b) Yes, each row can have a different length in a two-dimensional array.

**3. Java Variable Arguments explained**

1. What are variable arguments in Java?


a) Arguments passed to a method that are declared as variables.
b) Arguments that can have different data types in the same method.
c) Arguments that are passed using the "var" keyword.
d) Arguments that allow a method to accept a variable number of parameters.
Answer: d) Arguments that allow a method to accept a variable number of parameters.

2. How do you declare variable arguments in a Java method?


a) void methodName(var arg1, var arg2)
b) void methodName(... args)
c) void methodName(int... args)
d) void methodName(args...)
Answer: c) void methodName(int... args)

3. How can you access the variable arguments inside the method body?
a) By using the "args" keyword directly.
b) By accessing the arguments as an array using the "args" parameter name.
c) By using the "params" keyword inside the method body.
d) By passing the arguments individually to a separate method.
Answer: b) By accessing the arguments as an array using the "args" parameter name.

4. Can a Java method have other parameters along with variable arguments?
a) No, a method can only have either regular parameters or variable arguments, not both.
b) Yes, a method can have both regular parameters and variable arguments.
c) Yes, but only if the variable arguments are declared as "final."
d) No, variable arguments must be the only parameters in a method.
Answer: b) Yes, a method can have both regular parameters and variable arguments.

5. What is the advantage of using variable arguments in Java?


a) It allows a method to have multiple return values.
b) It reduces the number of overloaded methods needed for different parameter combinations.
c) It ensures that the method always receives a fixed number of arguments.
d) It allows a method to have a variable number of return statements.
Answer: b) It reduces the number of overloaded methods needed for different parameter
combinations.
**4. Add, update, read array elements**

1. How do you add an element to an array in Java?


a) By using the "+" operator to concatenate the new element to the array.
b) By using the "add" method provided by

the Array class.


c) By using the "add" method provided by the ArrayList class.
d) By directly assigning the new element to a specific index in the array.
Answer: d) By directly assigning the new element to a specific index in the array.

2. How do you update an element in an array in Java?


a) By using the "update" method provided by the Array class.
b) By directly assigning a new value to the existing element's index.
c) By using the "set" method provided by the ArrayList class.
d) By using the "set" method provided by the Array class.
Answer: b) By directly assigning a new value to the existing element's index.

3. How do you read an element from an array in Java?


a) By using the "read" method provided by the Array class.
b) By using the "get" method provided by the Array class.
c) By using the index of the element to access it directly.
d) By using the "get" method provided by the ArrayList class.
Answer: c) By using the index of the element to access it directly.

4. What happens if you try to read an element from an array using an index that is out of bounds?
a) The program will throw a runtime exception (ArrayIndexOutOfBoundsException).
b) The program will throw a compile-time error.
c) The program will return null for reference type elements or 0 for primitive type elements.
d) The program will automatically resize the array to accommodate the access.
Answer: a) The program will throw a runtime exception (ArrayIndexOutOfBoundsException).

5. How do you find the length of an array in Java?


a) By using the "length" property of the Array class.
b) By using the "length" method provided by the ArrayList class.
c) By using the "size" property of the Array class.
d) By using the "size" method provided by the ArrayList class.
Answer: a) By using the "length" property of the Array class.

**5. Sorting and searching in the array**

1. How can you sort an array in ascending order in Java?


a) By using the "sort" method provided by the Array class.
b) By using the "sort" method provided by the ArrayList class.
c) By using a loop to manually compare and swap elements.
d) By using the "sorted" method provided by the Array class.
Answer: a) By using the "sort" method provided by the Array class.

2. What is the time complexity of the quicksort algorithm used by the "sort" method in Java?
a) O(n)
b) O(n log n)
c) O(n^2)
d) O(log n)
Answer: b) O(n log n)

3. How can you search for a specific element in an array in Java?


a) By using the "search" method provided by the Array class.
b) By using the "find" method provided by the Array class.
c) By using the "indexOf" method provided by the Array class.
d) By using a loop to manually check each element.
Answer: d) By using a loop to manually check each element.

4. What is the time complexity of the linear search algorithm used to find an element in an array?
a) O(n)
b) O(n log n)
c) O(n^2)
d) O(log n)
Answer: a) O(n)

5. How can you perform a binary search on a sorted array in Java?


a) By using the "search" method provided by the Array class.
b) By using the "binarySearch" method provided by the Arrays class.
c) By using the "find" method provided by the Array class.
d) By using the "search" method provided by the ArrayList class.
Answer: b) By using the "binarySearch" method provided by the Arrays class.

**6. Java String Array to String**

1. How can you convert a Java String array to a single String with elements separated by a delimiter?
a) By using the "convertToString" method provided by the String class.
b) By using the "join" method provided by the Arrays class.
c) By using the "toString" method provided by the String class.
d) By manually concatenating each element with the delimiter.
Answer: b) By using the "join" method provided by the Arrays class.

2. What is the purpose of using a delimiter when converting a String array to a single String?
a) Delimiters are used to specify the length of the resulting String.
b) Delimiters are used to indicate the start and end of the String.
c) Delimiters are used to separate individual elements in the resulting String.
d) Delimiters are used to specify the data type of the elements in the array.
Answer: c) Delimiters are used to separate individual elements in the resulting String.

3. Which character(s) can be used as a delimiter in the "join" method for a String array?
a) Only commas (,)
b) Only spaces ( )
c) Any character or sequence of characters
d) Only semicolons (;)
Answer: c) Any character or sequence of characters

4. If a String array contains elements ["apple", "banana", "orange"], and the delimiter is "-", what will
be the resulting String?
a) "apple-banana-orange"
b) "apple,banana,orange"
c) "applebananaorange"
d) "apple/banana/orange"
Answer: a) "apple-banana-orange"

5. Can you specify an empty delimiter when using the "join" method on a String array?
a) No, the delimiter must always be a non-empty character or sequence.
b) Yes, an empty delimiter is allowed and will result in no separation between elements.
c) Yes, but only if the array is empty as well.
d) No, the "join" method does not allow delimiters for String arrays.
Answer: b) Yes, an empty delimiter is allowed and will result in no separation between elements.

**7. How to copy arrays in Java**


1. What is the correct way to copy an array in Java?
a) By using the "copy" method provided by the Arrays class.
b) By using the "clone" method provided by the Array class.
c) By manually copying each element to a new array.
d) By using the "copyOf" method provided by the Arrays class.
Answer: d) By using the "copyOf" method provided by the Arrays class.

2. When using the "copyOf" method to copy an array, do both arrays have the same memory address?
a) Yes, they both point to the same memory location.
b) No, the copied array is a shallow copy with a different memory address.
c) No, the copied array is a deep copy with a different memory address.
d) Yes, but only if the copied array is smaller in size than the original array.
Answer: b) No, the copied array is a shallow copy with a different memory address.

3. What happens if the "copyOf" method is used with a negative length parameter?
a) The method will throw a compile-time error.
b) The method will throw a runtime exception (NegativeArraySizeException).
c) The method will create an empty array with a length of 0.
d) The method will create an array with the absolute value of the length parameter.
Answer: b) The method will throw a runtime exception (NegativeArraySizeException).

4. How can you create a deep copy of a multidimensional array in Java?


a) By using the "deepCopy" method provided by the Arrays class.
b) By using nested loops to manually copy each element to a new array.
c) By using the "clone" method provided by the Array class.
d) By using the "copyOf" method provided by the Arrays class for each dimension.
Answer: b) By using nested loops to manually copy each element to a new array.

5. What is the main difference between a shallow copy and a deep copy of an array in Java?
a) A shallow copy maintains the same memory address for both arrays, while a deep copy creates a
new memory address for the copied array.
b) A shallow copy creates a new array with the same elements as the original array, while a deep
copy creates an empty array.
c) A shallow copy duplicates the original array, while a deep copy only duplicates the elements.
d) There is no difference; both terms refer to the same process of copying arrays.
Answer: a) A shallow copy maintains the same memory address for both arrays, while a deep copy
creates a new memory address for the copied array.
Concepts of Operating System
1. Lecture: Introduction to OS
**1. What is OS; How is it different from other application software; Why is it hardware dependent**

1. What does "OS" stand for in computing?


a) Online Software
b) Open Source
c) Operating System
d) Optimal Storage
Answer: c) Operating System

2. How is an Operating System (OS) different from other application software?


a) OS is used to manage hardware resources, while application software performs specific tasks for
users.
b) OS is designed for system administrators, while application software is designed for end-users.
c) OS is installed on servers, while application software is installed on personal computers.
d) OS is written in high-level programming languages, while application software is written in low-
level programming languages.
Answer: a) OS is used to manage hardware resources, while application software performs specific
tasks for users.

3. Why is an Operating System hardware-dependent?


a) OS is written in machine language, making it specific to the hardware architecture.
b) OS is installed on hardware components, making it reliant on their performance.
c) OS controls the hardware resources and interacts directly with them.
d) OS is developed by hardware manufacturers for their specific products.
Answer: c) OS controls the hardware resources and interacts directly with them.

4. What is the primary function of an Operating System?


a) To run application software efficiently.
b) To provide a user-friendly interface.
c) To manage hardware resources and provide an environment for executing applications.
d) To protect the computer from viruses and malware.
Answer: c) To manage hardware resources and provide an environment for executing applications.

5. Which of the following is an example of an application software?


a) Windows
b) Linux
c) Microsoft Office
d) macOS
Answer: c) Microsoft Office

6. What is the role of the BIOS (Basic Input/Output System) in computer organization for the OS?
a) It manages the computer's internal memory and ensures efficient data storage.
b) It provides a user-friendly interface for interacting with the OS.
c) It initializes hardware components and boots the operating system during startup.
d) It performs arithmetic and logical operations for the OS.
Answer: c) It initializes hardware components and boots the operating system during startup.

7. Which component of the OS is responsible for managing the execution of multiple processes and
allocating CPU time to each process?
a) File System
b) CPU Scheduler
c) Device Manager
d) Memory Allocator
Answer: b) CPU Scheduler

8. What are I/O devices in computer organization for the OS?


a) Devices used for internal memory management within the CPU.
b) Devices used for performing arithmetic and logical operations.
c) Devices used for inputting and outputting data to and from the computer.
d) Devices used for running application software and managing processes.
Answer: c) Devices used for inputting and outputting data to and from the computer.

**2. Different components of OS**

1. What are the main components of an Operating System?


a) Central Processing Unit (CPU) and Input/Output (I/O) devices.
b) File System, User Interface, and System Utilities.
c) Kernel, Shell, and Applications.
d) Memory Management, CPU Scheduling, and Device Management.
Answer: d) Memory Management, CPU Scheduling, and Device Management.

2. Which component of the OS is responsible for managing memory and ensuring efficient memory
allocation to processes?
a) File System
b) Memory Manager
c) CPU Scheduler
d) Device Manager
Answer: b) Memory Manager

3. What is the function of the File System component in an Operating System?


a) It manages the data stored in secondary storage devices.
b) It allocates and deallocates memory for processes and ensures efficient memory utilization.
c) It controls the flow of data between the CPU and I/O devices.
d) It provides a user-friendly interface for users to interact with the OS.
Answer: a) It manages the data stored in secondary storage devices.

4. Which component of the OS is responsible for controlling and coordinating the activities of
hardware devices?
a) File System
b) CPU Scheduler
c) Device Manager
d) Memory Allocator
Answer: c) Device Manager

5. How is an Operating System (OS) different from a compiler?


a) OS converts high-level programming code to machine code, while a compiler manages hardware
resources.
b) OS manages hardware resources, while a compiler translates high-level programming code into
machine code.
c) OS is used for data analysis, while a compiler is used for graphical interface development.
d) OS is used for code optimization, while a compiler provides a user-friendly interface for code
writing.
Answer: b) OS manages hardware resources, while a compiler translates high-level programming
code into machine code.

**3. Basic computer organization required for OS**

1. What is the role of the BIOS (Basic Input/Output System) in computer organization for the OS?
a) It manages the computer's internal memory and ensures efficient data storage.
b) It provides a user-friendly interface for interacting with the OS.
c) It initializes hardware components and boots the operating system during startup.
d) It performs arithmetic and logical operations for the OS.
Answer: c) It initializes hardware components and boots the operating system during startup.
2. What is the purpose of the Central Processing Unit (CPU) in computer organization for the OS?
a) To store data and programs permanently.
b) To manage and execute instructions stored in the computer's memory.
c) To provide a visual display of the OS interface on the screen.
d) To connect the computer to external devices like printers and scanners.
Answer: b) To manage and execute instructions stored in the computer's memory.

3. What are I/O devices in computer organization for the OS?


a) Devices used for internal memory management within the CPU.
b) Devices used for performing arithmetic and logical operations.
c) Devices used for inputting and outputting data to and from the computer.
d) Devices used for running application software and managing processes.
Answer: c) Devices used for inputting and outputting data to and from the computer.

4. Which of the following is an example of hardware in a computer system?


a) Operating System
b) Microsoft Office
c) Central Processing Unit (CPU)
d) Internet Explorer
Answer: c) Central Processing Unit (CPU)

5. What is the purpose of the motherboard in computer organization for the OS?
a) To manage the computer's internal memory and ensure efficient data storage.
b) To provide a user-friendly interface for interacting with the OS.
c) To connect the computer's hardware components and facilitate communication between them.
d) To perform arithmetic and logical operations for the OS.
Answer: c) To connect the computer's hardware components and facilitate communication between
them.

6. Which of the following components of a computer system is responsible for long-term storage of
data and programs?
a) CPU (Central Processing

Unit)
b) RAM (Random Access Memory)
c) Hard Disk Drive (HDD)
d) Motherboard
Answer: c) Hard Disk Drive (HDD)

7. What is the role of the Random Access Memory (RAM) in computer organization for the OS?
a) To store data and programs permanently.
b) To manage and execute instructions stored in the computer's memory.
c) To provide a visual display of the OS interface on the screen.
d) To connect the computer to external devices like printers and scanners.
Answer: b) To manage and execute instructions stored in the computer's memory.

8. Which of the following is an example of volatile memory in a computer system?


a) Hard Disk Drive (HDD)
b) Read-Only Memory (ROM)
c) Random Access Memory (RAM)
d) Central Processing Unit (CPU)
Answer: c) Random Access Memory (RAM)

**4. Examples of well-known OS including mobile OS, embedded system OS, Real Time OS, desktop
OS, server machine OS, etc.; How are these different from each other and why**

1. Which of the following is an example of a mobile operating system?


a) Windows
b) Linux
c) Android
d) macOS
Answer: c) Android

2. Which of the following is an example of an embedded system operating system?


a) iOS
b) Windows
c) Ubuntu
d) VxWorks
Answer: d) VxWorks

3. What is the main difference between a Real-Time Operating System (RTOS) and a desktop
operating system?
a) RTOS is designed for real-time data processing, while desktop OS is not.
b) Desktop OS is used in embedded systems, while RTOS is used in personal computers.
c) RTOS is designed for running desktop applications, while desktop OS is designed for real-time
processing.
d) Desktop OS is a type of RTOS designed specifically for graphics-intensive applications.
Answer: a) RTOS is designed for real-time data processing, while desktop OS is not.

4. How is a server machine operating system different from a desktop operating system?
a) Server OS is designed for real-time data processing, while desktop OS is not.
b) Server OS is optimized for managing network resources and handling multiple requests, while
desktop OS is optimized for individual user tasks.
c) Server OS is used only in data centers, while desktop OS is used on personal computers.
d) Server OS is open-source, while desktop OS is proprietary.
Answer: b) Server OS is optimized for managing network resources and handling multiple requests,
while desktop OS is optimized for individual user tasks.

5. Which of the following is an example of a desktop operating system?


a) iOS
b) Android
c) Windows
d) Ubuntu
Answer: c) Windows

6. What is the main difference between a mobile operating system and a desktop operating system?
a) Mobile OS is designed for real-time data processing, while desktop OS is not.
b) Mobile OS is optimized for touch-screen devices, while desktop OS is optimized for mouse and
keyboard input.
c) Mobile OS is used in servers, while desktop OS is used on personal computers.
d) Mobile OS is open-source, while desktop OS is proprietary.
Answer: b) Mobile OS is optimized for touch-screen devices, while desktop OS is optimized for
mouse and keyboard input.

7. What is the purpose of an embedded system operating system?


a) To run applications for end-users on personal computers.
b) To provide a user-friendly interface for interacting with the OS.
c) To manage hardware resources and run applications in specialized devices.
d) To protect the computer from viruses and malware.
Answer: c) To manage hardware resources and run applications in specialized devices.

8. Which of the following operating systems is commonly used in servers to manage network resources
and handle multiple requests?
a) Android
b) Windows
c) macOS
d) Linux
Answer: d) Linux
**5. Functions of OS**

1. Which of the following is a function of an Operating System?


a) Running application software efficiently.
b) Providing a user-friendly interface for users to interact with the OS.
c) Managing hardware resources and providing an environment for executing applications.
d) Protecting the computer from viruses and malware.
Answer: c) Managing hardware resources and providing an environment for executing applications.

2. What is the primary function of an Operating System (OS)?


a) To manage files and directories.
b) To provide a graphical user interface for users.
c) To protect the computer from malware and viruses.
d) To manage hardware resources and provide an interface for running applications.
Answer: d) To manage hardware resources and provide an interface for running applications.

3. Which function of the Operating System ensures fair and efficient utilization of the CPU among
multiple processes?
a) Memory Management
b) File Management
c) CPU Scheduling
d) Device Management
Answer: c) CPU Scheduling

4. What is the role of the File Management function in an Operating System?


a) It manages the computer's internal memory and ensures efficient data storage.
b) It provides a user-friendly interface for interacting with the OS.
c) It controls the flow of data between the CPU and I/O devices.
d) It handles the creation, deletion, and organization of files and directories.
Answer: d) It handles the creation, deletion, and organization of files and directories.

5. What function of the Operating System handles the communication and data transfer between the
computer and external devices like printers and scanners?
a) CPU Scheduling
b) Memory Management
c) File Management
d) Device Management
Answer: d) Device Management

6. Which function of the Operating System is responsible for allocating and deallocating memory for
processes to ensure efficient memory utilization?
a) Memory Management
b) CPU Scheduling
c) File Management
d) Device Management
Answer: a) Memory Management

7. Which of the following is NOT a function of an Operating System?


a) Memory Management
b) CPU Scheduling
c) File Sharing
d) Device Management
Answer: c) File Sharing

8. Which of the following functions of the Operating System is responsible for handling user requests
and providing a graphical user interface?
a) Memory Management
b) CPU Scheduling
c) File Management
d) User Interface
Answer: d) User Interface

**6. User and Kernel space and mode; Interrupts and system calls**

1. What are the two distinct execution modes in an Operating System?


a) User mode and Kernel mode
b) Real mode and Protected mode
c) 32-bit mode and 64-bit mode
d) High privilege mode and Low privilege mode
Answer: a) User mode and Kernel mode

2. In which mode does the CPU execute the user applications and non-privileged code in the Operating
System?
a) User mode
b) Kernel mode
c) Real mode
d) Protected mode

Answer: a) User mode

3. In which mode does the CPU execute the core operating system functions and privileged instructions?
a) User mode
b) Kernel mode
c) Real mode
d) Protected mode
Answer: b) Kernel mode

4. Which of the following is responsible for switching the CPU between User mode and Kernel mode?
a) System calls
b) Interrupts
c) CPU scheduler
d) Device drivers
Answer: a) System calls

5. What is the purpose of a system call in an Operating System?


a) To switch the CPU from Kernel mode to User mode.
b) To allow user applications to access hardware directly.
c) To request services from the operating system kernel.
d) To handle interrupts caused by hardware devices.
Answer: c) To request services from the operating system kernel.

6. Which of the following is used by the CPU to handle hardware interrupts and perform context
switches?
a) System calls
b) CPU scheduler
c) Interrupt controller
d) Device drivers
Answer: c) Interrupt controller

7. What is the purpose of the CPU scheduler in an Operating System?


a) To switch the CPU from User mode to Kernel mode.
b) To handle system calls and provide services to user applications.
c) To allocate CPU time to processes and perform context switches.
d) To manage the execution of user applications and non-privileged code.
Answer: c) To allocate CPU time to processes and perform context switches.
8. Which of the following is responsible for managing hardware devices and providing an interface for
them to communicate with the CPU?
a) System calls
b) CPU scheduler
c) Interrupt controller
d) Device drivers
Answer: d) Device drivers
2. Lecture: Introduction to Linux
**1. Working basics of the file system**

1. What is the file system in an operating system?


a) A hardware component used for storing files and directories.
b) A software component responsible for managing files and organizing data on storage devices.
c) A user interface for interacting with files and directories.
d) A programming language used for file manipulation.
Answer: b) A software component responsible for managing files and organizing data on storage
devices.

2. Which of the following is NOT a basic operation supported by the file system?
a) Create
b) Modify
c) Move
d) Print
Answer: d) Print

3. What is a directory in the file system?


a) A single file that contains multiple folders.
b) A collection of files and subdirectories.
c) A special type of file used for storing system settings.
d) A file that cannot be accessed or modified by users.
Answer: b) A collection of files and subdirectories.

4. What is the purpose of a file path in the file system?


a) To specify the location of a file or directory in the file system hierarchy.
b) To encrypt the contents of a file for security purposes.
c) To rename a file or directory.
d) To compress a file to reduce its size.
Answer: a) To specify the location of a file or directory in the file system hierarchy.

5. Which file system feature helps prevent data loss by keeping track of data changes before they are
permanently written to disk?
a) File encryption
b) File compression
c) Journaling
d) File indexing
Answer: c) Journaling

6. What does the "ls" command do in Linux/Unix?


a) List all installed applications on the system.
b) Create a new file in the current directory.
c) List the contents of a directory.
d) Remove a file from the system.
Answer: c) List the contents of a directory.

7. What does the "cp" command do in Linux/Unix?


a) Copy a file from one location to another.
b) Create a new file in the current directory.
c) Move a file to a different directory.
d) Remove a file from the system.
Answer: a) Copy a file from one location to another.

8. What is the purpose of the "rm" command in Linux/Unix?


a) Rename a file or directory.
b) Copy a file from one location to another.
c) Remove a file or directory from the system.
d) Move a file to a different directory.
Answer: c) Remove a file or directory from the system.

**2. Commands associated with files/directories & other basic commands. Operators like redirection,
pipe**

1. What is the purpose of the ">" operator in the context of command-line redirection?
a) It redirects the input of a command from a file.
b) It redirects the output of a command to a new file, overwriting the file if it exists.
c) It redirects the output of a command to a new file, appending the output if the file exists.
d) It combines the output of multiple commands into a single file.
Answer: b) It redirects the output of a command to a new file, overwriting the file if it exists.

2. Which command is used to create a new directory in Linux/Unix?


a) dir
b) cd
c) mkdir
d) ls
Answer: c) mkdir

3. What does the "|" symbol do in Linux/Unix shell commands?


a) It redirects the output of a command to a file.
b) It sends the command to the background, allowing other commands to be executed concurrently.
c) It combines multiple commands into a single command line.
d) It pipes the output of one command as input to another command.
Answer: d) It pipes the output of one command as input to another command.

4. How can you view the content of a file in Linux/Unix?


a) cat filename
b) echo filename
c) view filename
d) open filename
Answer: a) cat filename

5. What does the ">>" operator do in the context of command-line redirection?


a) It redirects the input of a command from a file.
b) It redirects the output of a command to a new file, overwriting the file if it exists.
c) It redirects the output of a command to a new file, appending the output if the file exists.
d) It combines the output of multiple commands into a single file.
Answer: c) It redirects the output of a command to a new file, appending the output if the file exists.

6. Which command is used to remove a directory in Linux/Unix?


a) rmdir
b) rmfile
c) rm
d) delete
Answer: a) rmdir

7. How can you create a new file in Linux/Unix?


a) create filename
b) echo "" > filename
c) newfile filename

d) touch filename
Answer: d) touch filename

8. What does the "cd" command do in Linux/Unix?


a) List the contents of a directory.
b) Create a new directory.
c) Change the current working directory.
d) Copy a file from one location to another.
Answer: c) Change the current working directory.

**3. What are file permissions and how to set them**

1. What are file permissions in the context of Linux/Unix?


a) Rules for accessing files over a network.
b) Properties that define the size and location of a file.
c) Settings that control who can read, write, and execute a file.
d) Access control list for managing file ownership.
Answer: c) Settings that control who can read, write, and execute a file.

2. How are file permissions represented in Linux/Unix?


a) A single character (r, w, x) for each permission.
b) A combination of numbers (0-7) representing the permissions.
c) A combination of letters (R, W, X) representing the permissions.
d) A combination of symbols (+, -, =) representing the permissions.
Answer: a) A single character (r, w, x) for each permission.

3. Which permission allows a user to read the contents of a file in Linux/Unix?


a) r
b) w
c) x
d) u
Answer: a) r

4. How can you change file permissions in Linux/Unix using the "chmod" command?
a) chmod new_permissions file_name
b) chmod file_name new_permissions
c) chmod permissions new_file_name
d) chmod file_name permissions
Answer: a) chmod new_permissions file_name

5. What does the "r" permission indicate for a file in Linux/Unix?


a) The file can be read.
b) The file can be written.
c) The file can be executed.
d) The file can be moved.
Answer: a) The file can be read.

6. How are file permissions displayed when using the "ls -l" command in Linux/Unix?
a) A series of numbers representing the permissions.
b) A combination of letters (r, w, x) representing the permissions.
c) A series of dashes and letters (r, w, x) representing the permissions.
d) A series of symbols (+, -, =) representing the permissions.
Answer: c) A series of dashes and letters (r, w, x) representing the permissions.

7. What does the "w" permission indicate for a file in Linux/Unix?


a) The file can be read.
b) The file can be written.
c) The file can be executed.
d) The file can be moved.
Answer: b) The file can be written.

8. How can you set the read and write permissions for the owner of a file in Linux/Unix using the
"chmod" command?
a) chmod rw file_name
b) chmod u+rw file_name
c) chmod +rw file_name
d) chmod u=rw file_name
Answer: b) chmod u+rw file_name

**4. Permissions (chmod, chown, etc); access control list; network commands (telnet, ftp, ssh, sftp,
finger)**

1. What is the purpose of the "chmod" command in Linux/Unix?


a) It is used to change the ownership of a file or directory.
b) It is used to change file permissions (read, write, execute) for users, groups, and others.
c) It is used to compress files and directories to save disk space.
d) It is used to copy files and directories from one location to another.
Answer: b) It is used to change file permissions (read, write, execute) for users, groups, and others.

2. Which command is used to change the ownership of a file or directory in Linux/Unix?


a) chown
b) chmod
c) chgrp
d) own
Answer: a) chown

3. What does the "chgrp" command do in Linux/Unix?


a) It changes the ownership of a file or directory to a specified user.
b) It changes the ownership of a file or directory to a specified group.
c) It changes the group permissions of a file or directory.
d) It changes the file permissions to be executable by everyone.
Answer: c) It changes the group permissions of a file or directory.

4. What does the "ls -l" command display in Linux/Unix?


a) A list of all installed applications on the system.
b) A list of currently running processes.
c) A list of files and directories with their permissions, owners, and sizes.
d) A list of system variables and their values.
Answer: c) A list of files and directories with their permissions, owners, and sizes.

5. How can you grant read and write permissions to the owner and the group for a file named "data.txt"
in Linux/Unix?
a) chmod u+rw,g+rw data.txt
b) chmod ug+rw data.txt
c) chmod u=rw,g=rw data.txt
d) chmod rw,grw data.txt
Answer: a) chmod u+rw,g+rw data.txt

6. What is an access control list (ACL) in the context of file permissions?


a) A list of banned users who are not allowed to access the file or directory.
b) A list of authorized users who have special permissions on the file or directory.
c) A list of system variables used to control file access.
d) A list of system services that have access to the file or directory.
Answer: b) A list of authorized users who have special permissions on the file or directory.

7. Which network command is used for secure remote login and execution of commands in Linux/Unix?
a) telnet
b) ftp
c) ssh
d) finger
Answer: c) ssh

8. How does the "finger" command work in Linux/Unix?


a) It displays information about users currently logged into the system.
b) It shows the content of a file on the screen.
c) It compresses files to save disk space.
d) It transfers files between a local and remote system.
Answer: a) It displays information about users currently logged into the system.

**5. System variables like – PS1, PS2, etc. How to set them**

1. What are system variables in Linux/Unix?


a) Variables used by the kernel to manage system resources.
b) Variables used by the operating system to store user preferences and configurations.
c) Variables used by system administrators to control network settings.
d) Variables used by application software to store temporary data.
Answer: b) Variables used by the operating system to store user preferences and configurations.

2. Which system variable is used to define the primary command prompt in the Linux/Unix shell?
a) PS1
b) PS2
c) PS3
d) PS4
Answer: a) PS1

3. What is the purpose of the "PS2" system variable in Linux/Unix?


a) To define the secondary command prompt in the shell.
b) To set the system-wide path for executable files.
c) To configure the default text editor for the system.
d) To specify the default home directory for new users.
Answer: a) To define the secondary command prompt in the shell.

4. Which command is used to view the current values of system variables in Linux/Unix?
a) env
b) ls
c) set
d) echo
Answer: a) env

5. How can you set the value of a system variable like "PS1" in Linux/Unix?
a) Using the "export" command followed by the variable name and its value.
b) By modifying the system configuration file.
c) By creating a new user account with the desired variable settings.
d) By running the "source" command followed by the variable name and its value.
Answer: a) Using the "export" command followed by the variable name and its value.

6. What is the purpose of the "PS3" system variable in Linux/Unix?


a) To define the primary command prompt in the shell.
b) To set the system-wide path for executable files.
c) To configure the default text editor for the system.
d) To specify the default home directory for new users.
Answer: c) To configure the default text editor for the system.

7. Which system variable is used to define the prompt used by the shell when reading a line with the
"read" command?
a) PS1
b) PS2

c) PS3
d) PS4
Answer: c) PS3
8. How can you set the value of a system variable like "PS2" permanently in Linux/Unix?
a) By modifying the system configuration file.
b) By running the "export" command followed by the variable name and its value.
c) By creating a new user account with the desired variable settings.
d) By using the "unset" command to remove the current value of the variable.
Answer: a) By modifying the system configuration file.
3. Shell Programming

**1. What is shell; What are different shells in Linux?**

1. What is the shell in the context of Linux/Unix operating systems?


a) It is a hardware component responsible for data storage.
b) It is a software component responsible for managing files and directories.
c) It is a user interface that allows users to interact with the operating system.
d) It is a command-line interpreter that interprets user commands and executes them.
Answer: d) It is a command-line interpreter that interprets user commands and executes them.

2. Which of the following is NOT a popular shell used in Linux/Unix?


a) Bash
b) Csh
c) Tsh
d) Zsh
Answer: c) Tsh

3. What is the default shell in most Linux distributions?


a) Bash
b) Csh
c) Zsh
d) Ksh
Answer: a) Bash

4. Which shell is known for its enhanced features and improved command-line editing capabilities?
a) Bash
b) Csh
c) Zsh
d) Ksh
Answer: c) Zsh

5. What is the primary function of the shell in Linux/Unix?


a) To manage hardware resources and provide an environment for running applications.
b) To provide a graphical user interface for interacting with the OS.
c) To manage files and directories.
d) To interpret user commands and execute them.
Answer: d) To interpret user commands and execute them.

6. Which shell is designed to be compatible with the Bourne shell (sh) and includes additional features?
a) Bash
b) Csh
c) Zsh
d) Ksh
Answer: a) Bash

7. What is the role of the shell prompt in the command-line interface?


a) To indicate the current working directory.
b) To display the available system resources.
c) To list the running processes.
d) To provide suggestions for command completion.
Answer: a) To indicate the current working directory.

8. Which shell is considered a C-like shell and was developed as an alternative to the Bourne shell?
a) Bash
b) Csh
c) Zsh
d) Ksh
Answer: b) Csh
9. How can you switch to a different shell in a Linux terminal?
a) Run the "shell" command and specify the desired shell name.
b) Modify the system configuration file to set the default shell.
c) Install the new shell using the package manager and then restart the terminal.
d) Use the "chsh" command to change the default shell for the current user.
Answer: d) Use the "chsh" command to change the default shell for the current user.

10. What are the advantages of using different shells in Linux/Unix?


a) Different shells provide different user interfaces.
b) Each shell has its own set of features and capabilities.
c) Different shells can improve command-line productivity for specific tasks.
d) All of the above.
Answer: d) All of the above.

**2. Shell variables; Wildcard symbols**

1. What are shell variables in Linux/Unix?


a) Variables used by the kernel to manage system resources.
b) Variables used by the operating system to store user preferences and configurations.
c) Variables used by system administrators to control network settings.
d) Variables used by application software to store temporary data.
Answer: b) Variables used by the operating system to store user preferences and configurations.

2. How can you set the value of a shell variable in Linux/Unix?


a) Using the "export" command followed by the variable name and its value.
b) By modifying the system configuration file.
c) By creating a new user account with the desired variable settings.
d) By running the "source" command followed by the variable name and its value.
Answer: d) By running the "source" command followed by the variable name and its value.

3. What is the purpose of using shell variables in Linux/Unix?


a) To define the primary command prompt in the shell.
b) To store temporary data during script execution.
c) To define the secondary command prompt in the shell.
d) To manage file permissions in the file system.
Answer: b) To store temporary data during script execution.

4. Which symbol is used as a wildcard to represent any character in Linux/Unix shell commands?
a) *
b) #
c) !
d) @
Answer: a) *

5. What does the wildcard symbol "?" represent in Linux/Unix shell commands?
a) It represents zero or more characters.
b) It represents one or more characters.
c) It represents any single character.
d) It represents the current user's home directory.
Answer: c) It represents any single character.

6. Which wildcard symbol is used to match any sequence of characters, including none?
a) ?
b) *
c) !
d) @
Answer: b) *

7. How can you use a shell variable in a command-line command in Linux/Unix?


a) Enclose the variable name in single quotes.
b) Enclose the variable name in double quotes.
c) Precede the variable name with a dollar sign ($).
d) Place the variable name between square brackets [ ].
Answer: c) Precede the variable name with a dollar sign ($).

8. What is the purpose of the wildcard symbol "[" in Linux/Unix shell commands?
a) It represents any single character.
b) It is used to enclose command options.
c) It is used to enclose command arguments.
d) It is used to define a character range for matching.
Answer: d) It is used to define a character range for matching.

**3. Shell meta characters; Command-line arguments; Read, Echo**

1. What are shell meta characters in Linux/Unix?


a) Special characters that have a specific meaning in the shell.
b) Variables used by the shell to store user preferences and configurations.
c) Wildcard symbols used for pattern matching.
d) Reserved words that cannot be used as file or directory names.
Answer: a) Special characters that have a specific meaning in the shell.

2. Which meta character is used to redirect the output of a command to a file in Linux/Unix?
a) >
b) &
c) |
d) $
Answer: a) >

3. How can you pass command-line arguments to a shell script in Linux/Unix?


a) By defining variables in the script to store the arguments.
b) By placing the arguments after the script name when executing the script.
c) By using the "set" command to set the arguments before running the script.
d) By using the "getopts" command to fetch the arguments within the script.
Answer: b) By placing the arguments after the script name when executing the script.

4. Which command is used to read input from the user in a

shell script?
a) input
b) read
c) user
d) fetch
Answer: b) read

5. How can you display a message on the screen in a shell script?


a) print
b) display
c) echo
d) show
Answer: c) echo

6. What is the purpose of the "echo" command in Linux/Unix shell scripts?


a) To display the current date and time.
b) To list the files in the current directory.
c) To display messages or variables on the screen.
d) To execute a system command.
Answer: c) To display messages or variables on the screen.
7. What does the "&" symbol do in Linux/Unix shell commands?
a) It redirects the output of a command to a file.
b) It sends the command to the background, allowing other commands to be executed concurrently.
c) It combines multiple commands into a single command line.
d) It represents any single character in wildcard matching.
Answer: b) It sends the command to the background, allowing other commands to be executed
concurrently.

8. Which meta character is used to pipe the output of one command as input to another command in
Linux/Unix?
a) >
b) <
c) |
d) &
Answer: c) |

**4. Decision loops (if else, test, nested if else, case controls, while...until, for)**

1. Which control structure allows a program to execute a set of statements repeatedly as long as a
certain condition is true?
a) if else loop
b) while loop
c) nested loop
d) for loop
Answer: b) while loop

2. What is the purpose of the "else" statement in the if-else control structure?
a) It allows the program to execute a set of statements repeatedly.
b) It allows the program to perform different actions based on a condition.
c) It specifies the condition to be tested in the loop.
d) It executes a set of statements if the condition in the "if" part is false.
Answer: d) It executes a set of statements if the condition in the "if" part is false.

3. In a nested if-else statement, how many conditions can be tested?


a) Only one condition can be tested.
b) Two conditions can be tested.
c) Three or more conditions can be tested.
d) There is no limit to the number of conditions that can be tested.
Answer: c) Three or more conditions can be tested.

4. Which control structure is used to perform different actions based on the value of a variable or an
expression?
a) if else loop
b) test control
c) nested if else
d) case control
Answer: d) case control

5. What is the purpose of a "break" statement in a switch-case control structure?


a) It terminates the entire loop.
b) It terminates the current iteration of the loop and continues to the next iteration.
c) It specifies the condition to be tested in the loop.
d) It exits the switch-case structure and continues with the next statement after the switch.
Answer: d) It exits the switch-case structure and continues with the next statement after the switch.

6. Which control structure is used to execute a set of statements repeatedly until a certain condition
becomes true?
a) while loop
b) until loop
c) for loop
d) nested loop
Answer: b) until loop

7. How many times will a "for" loop iterate if the loop condition is false initially?
a) Zero times
b) One time
c) Infinite times
d) It depends on the loop body statements.
Answer: a) Zero times

8. In a "for" loop, what is the role of the loop control variable?


a) It holds the value of the loop condition.
b) It stores the result of the loop body.
c) It determines the number of iterations for the loop.
d) It holds the result of the arithmetic expression.
Answer: c) It determines the number of iterations for the loop.

**5. Regular expressions; Arithmetic expressions**

1. What are regular expressions used for in programming?


a) To perform complex arithmetic calculations.
b) To define patterns and match strings.
c) To create nested if-else statements.
d) To handle file I/O operations.
Answer: b) To define patterns and match strings.

2. Which symbol is used to represent any character in a regular expression?


a) *
b) ?
c) .
d) #
Answer: c) .

3. What is the purpose of the "+" symbol in a regular expression?


a) It matches the preceding character zero or one time.
b) It matches the preceding character zero or more times.
c) It matches the preceding character one or more times.
d) It matches the preceding character exactly n times.
Answer: c) It matches the preceding character one or more times.

4. In a regular expression, what does the "^" symbol represent?


a) The start of a line.
b) The end of a line.
c) A word boundary.
d) An escape character.
Answer: a) The start of a line.

5. Which arithmetic operator is used for exponentiation in most programming languages?


a) +
b) -
c) *
d) **
Answer: d) **

6. What is the result of the arithmetic expression "5 + 3 * 2"?


a) 16
b) 11
c) 13
d) 26
Answer: c) 13

7. In an arithmetic expression, what is the purpose of using parentheses "( )"?


a) To indicate the beginning and end of the expression.
b) To perform addition and subtraction operations.
c) To give priority to certain operations.
d) To represent a variable.
Answer: c) To give priority to certain operations.

8. What is the value of the arithmetic expression "10 / 2 + 3 * (8 - 5)"?


a) 21
b) 12
c) 9
d) 15
Answer: b) 12
4. Lecture: Processes
**1. What is a process; preemptive and non-preemptive processes**

1. What is a process in the context of an operating system?


a) A single user interacting with the system.
b) A program in execution along with its current state.
c) A set of instructions waiting to be executed.
d) A storage area used for temporary data.
Answer: b) A program in execution along with its current state.

2. What is a preemptive process scheduling strategy?


a) The process voluntarily gives up the CPU for other processes to execute.
b) The operating system forcibly removes the CPU from a process and allocates it to another process.
c) The process executes until it reaches a blocking operation.
d) The process executes until its time slice expires.
Answer: b) The operating system forcibly removes the CPU from a process and allocates it to another
process.

3. In non-preemptive process scheduling, when does a process release the CPU?


a) When it completes its execution.
b) When it enters the waiting state.
c) When it reaches a blocking operation.
d) When its time slice expires.
Answer: a) When it completes its execution.

4. Which type of process scheduling allows processes to be interrupted and moved between the running
and ready state?
a) Preemptive process scheduling
b) Non-preemptive process scheduling
c) Priority-based process scheduling
d) Round-robin process scheduling
Answer: a) Preemptive process scheduling

5. What is the main advantage of preemptive process scheduling over non-preemptive scheduling?
a) It allows for a higher degree of parallelism.
b) It reduces context switching overhead.
c) It provides fairness among all processes.
d) It allows for better response time in a multi-programmed environment.
Answer: d) It allows for better response time in a multi-programmed environment.

6. Which type of process scheduling is used in real-time operating systems?


a) Preemptive process scheduling
b) Non-preemptive process scheduling
c) Round-robin process scheduling
d) Priority-based process scheduling
Answer: a) Preemptive process scheduling

7. What happens to a process that is in the running state when it gets preempted?
a) It moves to the waiting state.
b) It moves to the ready state.
c) It moves to the terminated state.
d) It moves to the new state.
Answer: b) It moves to the ready state.

**2. Process management; Process life cycle**

1. What is process management in the context of an operating system?


a) Managing the allocation of CPU resources to processes.
b) Managing the input and output operations of a process.
c) Managing the creation and termination of processes.
d) Managing the memory utilization of processes.
Answer: c) Managing the creation and termination of processes.

2. In the process life cycle, which state represents a process that has been created but not yet admitted
to the main memory?
a) New state
b) Ready state
c) Running state
d) Terminated state
Answer: a) New state

3. Which state in the process life cycle represents a process that is currently executing on the CPU?
a) New state
b) Ready state
c) Running state
d) Terminated state
Answer: c) Running state

4. What happens to a process in the ready state when it gets selected by the scheduler to run on the
CPU?
a) It moves to the new state.
b) It moves to the waiting state.
c) It moves to the running state.
d) It moves to the terminated state.
Answer: c) It moves to the running state.

5. In the process life cycle, what does the terminated state represent?
a) The process has completed its execution successfully.
b) The process has encountered an error and terminated prematurely.
c) The process is waiting for an event to occur.
d) The process is waiting for a resource to be released.
Answer: a) The process has completed its execution successfully.

6. How does a process in the waiting state move to the ready state?
a) When its time slice expires in a round-robin scheduling algorithm.
b) When it is preempted by a higher-priority process.
c) When it completes its execution.
d) When the event it is waiting for occurs.
Answer: d) When the event it is waiting for occurs.

7. What is the main purpose of the process life cycle in an operating system?
a) To ensure that all processes get an equal share of CPU time.
b) To manage the creation and termination of processes efficiently.
c) To allow processes to communicate with each other.
d) To prevent processes from entering the waiting state.
Answer: b) To manage the creation and termination of processes efficiently.

**3. What are schedulers – Short term, Medium term and Long term.**

1. What is the role of the short-term scheduler (CPU scheduler) in the process scheduling hierarchy?
a) It selects processes from the job queue to be loaded into main memory.
b) It selects processes from the ready queue to run on the CPU.
c) It selects processes from the blocked queue to be moved to the ready queue.
d) It selects processes from the new queue to be moved to the job queue.
Answer: b) It selects processes from the ready queue to run on the CPU.
2. Which scheduler is responsible for determining the order in which processes are executed in a multi-
programmed environment?
a) Short-term scheduler
b) Medium-term scheduler
c) Long-term scheduler
d) High-level scheduler
Answer: a) Short-term scheduler

3. What is the primary objective of the short-term scheduler (CPU scheduler)?


a) To maximize CPU utilization.
b) To minimize the waiting time of processes.
c) To allocate CPU time equally to all processes.
d) To determine the priority of processes.
Answer: b) To minimize the waiting time of processes.

4. What is the role of the medium-term scheduler in process scheduling?


a) To swap out processes from main memory to secondary storage.
b) To select processes from the job queue to be loaded into main memory.
c) To select processes from the ready queue to run on the CPU.
d) To select processes from the blocked queue to be moved to the ready queue.
Answer: a) To swap out processes from main memory to secondary storage.

5. What is the primary objective of the medium-term scheduler?


a) To maximize CPU utilization.
b) To minimize the waiting time of processes.
c) To manage the process memory efficiently.
d) To determine the priority of processes.
Answer: c) To manage the process memory efficiently.

6. Which scheduler is responsible for determining which processes should be admitted into the main
memory from the job queue?
a) Short-term scheduler
b) Medium-term scheduler
c) Long-term scheduler

d) High-level scheduler
Answer: c) Long-term scheduler

7. In the process scheduling hierarchy, what is the role of the long-term scheduler (job scheduler)?
a) To allocate CPU time equally to all processes.
b) To select processes from the ready queue to run on the CPU.
c) To determine the priority of processes.
d) To select processes from the job queue to be loaded into main memory.
Answer: d) To select processes from the job queue to be loaded into main memory.

**4. Process scheduling algorithms – FCFS, Shortest Job First, Priority, RR, Queue. Belady’s
Anomaly**

1. Which process scheduling algorithm allocates the CPU to the process that arrives first in the ready
queue?
a) FCFS (First-Come, First-Served)
b) SJF (Shortest Job First)
c) Priority scheduling
d) Round-robin scheduling
Answer: a) FCFS (First-Come, First-Served)

2. What is the main disadvantage of the FCFS (First-Come, First-Served) scheduling algorithm?
a) It can lead to starvation of low-priority processes.
b) It may result in poor average waiting time for processes.
c) It does not allow for process preemption.
d) It does not support multi-programming.
Answer: b) It may result in poor average waiting time for processes.

3. In the Shortest Job First (SJF) scheduling algorithm, which process gets selected to run on the CPU?
a) The process with the highest priority.
b) The process with the shortest burst time.
c) The process with the largest burst time.
d) The process with the longest waiting time.
Answer: b) The process with the shortest burst time.

4. What is the main advantage of the SJF (Shortest Job First) scheduling algorithm?
a) It guarantees that all processes get an equal share of CPU time.
b) It provides the highest priority to interactive processes.
c) It reduces context switching overhead.
d) It minimizes the average waiting time for processes.
Answer: d) It minimizes the average waiting time for processes.

5. What is the criteria used to select the process to run in priority scheduling?
a) The process with the shortest burst time.
b) The process with the highest priority value.
c) The process with the largest burst time.
d) The process with the lowest priority value.
Answer: b) The process with the highest priority value.

6. What is the time quantum in the Round-Robin (RR) scheduling algorithm?


a) The time taken to execute a process on the CPU.
b) The time taken to perform a context switch.
c) The maximum time a process is allowed to run on the CPU before being preempted.
d) The total time taken by all processes in the ready queue to complete their execution.
Answer: c) The maximum time a process is allowed to run on the CPU before being preempted.

7. What is Belady’s Anomaly in the context of the FIFO (First-In-First-Out) page replacement
algorithm?
a) The page fault rate increases with the increase in the number of frames.
b) The page fault rate decreases with the increase in the number of frames.
c) The page fault rate remains constant regardless of the number of frames.
d) The page fault rate fluctuates randomly with the number of frames.
Answer: a) The page fault rate increases with the increase in the number of frames.

**5. Examples associated with scheduling algorithms to find turnaround time to find the better
performing scheduler.**

1. Which scheduling algorithm typically has the shortest turnaround time for a mix of long and short
CPU burst time processes?
a) FCFS (First-Come, First-Served)
b) SJF (Shortest Job First)
c) Priority scheduling
d) Round-robin scheduling
Answer: b) SJF (Shortest Job First)

2. Consider three processes P1, P2, and P3 with burst times of 4, 7, and 2 units, respectively. Which
scheduling algorithm results in the shortest average turnaround time?
a) FCFS (First-Come, First-Served)
b) SJF (Shortest Job First)
c) Priority scheduling
d) Round-robin scheduling
Answer: b) SJF (Shortest Job First)
3. Which scheduling algorithm is most suitable for time-sharing systems where interactive processes
require quick response time?
a) FCFS (First-Come, First-Served)
b) SJF (Shortest Job First)
c) Priority scheduling
d) Round-robin scheduling
Answer: d) Round-robin scheduling

4. Consider three processes P1, P2, and P3 with burst times of 8, 3, and 5 units, respectively, and a time
quantum of 4 units for the Round-Robin scheduling algorithm. What is the turnaround time for process
P1?
a) 5 units
b) 8 units
c) 10 units
d) 12 units
Answer: d) 12 units

5. In priority scheduling, what happens if two processes have the same priority value?
a) The process with the longest burst time gets selected.
b) The process that arrives first in the ready queue gets selected.
c) The process with the shortest burst time gets selected.
d) The process with the largest burst time gets selected.
Answer: b) The process that arrives first in the ready queue gets selected.

6. Consider three processes P1, P2, and P3 with burst times of 6, 4, and 8 units, respectively, and
priorities of 3, 2, and 1, respectively. Which scheduling algorithm results in the shortest average
turnaround time?
a) FCFS (First-Come, First-Served)
b) SJF (Shortest Job First)
c) Priority scheduling
d) Round-robin scheduling
Answer: c) Priority scheduling

7. In priority scheduling, which process gets selected to run on the CPU if all processes have the same
priority value?
a) The process with the longest burst time.
b) The process that arrives first in the ready queue.
c) The process with the shortest burst time.
d) The process with the largest burst time.
Answer: b) The process that arrives first in the ready queue.

**6. Process creation using fork; waitpid and exec system calls; Examples on process creation; Parent
and child processes**

1. Which system call is used to create a new process in Linux/Unix?


a) fork
b) waitpid
c) exec
d) create
Answer: a) fork

2. What happens when the fork system call is executed in a program?


a) It creates a new process that is an exact copy of the calling process.
b) It waits for a child process to complete its execution.
c) It loads a new program into the memory.
d) It executes a system call in the child process.
Answer:
a) It creates a new process that is an exact copy of the calling process.

3. Which system call is used to wait for a specific child process to terminate in Linux/Unix?
a) fork
b) waitpid
c) exec
d) create
Answer: b) waitpid

4. What is the primary purpose of the exec system call?


a) To create a new process.
b) To terminate a process.
c) To wait for a child process to complete its execution.
d) To load a new program into the current process's memory space.
Answer: d) To load a new program into the current process's memory space.

5. In process creation using the fork system call, what is the relationship between the parent and child
processes?
a) The parent and child processes are independent of each other.
b) The parent process terminates before the child process starts executing.
c) The parent and child processes share the same memory space.
d) The parent process executes after the child process completes its execution.
Answer: c) The parent and child processes share the same memory space.

6. In process creation using the fork system call, how many processes are created after the fork call?
a) Only one process is created.
b) Two processes are created - the parent and the child.
c) Three processes are created - the parent, the child, and the grandchild.
d) The number of processes created depends on the number of fork calls.
Answer: b) Two processes are created - the parent and the child.

7. In process creation using the fork system call, what is the value returned by the fork call in the parent
process?
a) 0
b) 1
c) The process ID of the child process
d) The process ID of the parent process
Answer: c) The process ID of the child process.

**7. Orphan and zombie processes**

1. What is an orphan process in the context of an operating system?


a) A process that has completed its execution.
b) A process that is waiting for an event to occur.
c) A process that is waiting for a resource to be released.
d) A process whose parent process has terminated.
Answer: d) A process whose parent process has terminated.

2. What happens to an orphan process in the operating system?


a) It becomes a zombie process.
b) It is terminated by the operating system.
c) It continues its execution independently as an independent process.
d) It waits for a new parent process to adopt it.
Answer: d) It waits for a new parent process to adopt it.

3. What is a zombie process in the context of an operating system?


a) A process that has completed its execution.
b) A process that is waiting for an event to occur.
c) A process that is waiting for a resource to be released.
d) A process that has terminated, but its process table entry still exists.
Answer: d) A process that has terminated, but its process table entry still exists.

4. What happens to a zombie process in the operating system?


a) It is terminated by the operating system.
b) It continues its execution independently as an independent process.
c) It waits for a new parent process to adopt it.
d) It is assigned to a new parent process.
Answer: a) It is terminated by the operating system.

5. What is the main cause of a zombie process in an operating system?


a) Insufficient memory to allocate new processes.
b) A programming error that causes the process to enter an infinite loop.
c) A bug in the operating system kernel.
d) A parent process failing to call the wait system call to retrieve the exit status of its child process.
Answer: d) A parent process failing to call the wait system call to retrieve the exit status of its child
process.

6. What is the purpose of the wait system call in an operating system?


a) To wait for a child process to complete its execution.
b) To wait for an event to occur.
c) To wait for a resource to be released.
d) To terminate the current process.
Answer: a) To wait for a child process to complete its execution.

7. How can a zombie process be prevented in an operating system?


a) By using the kill system call to terminate the process.
b) By using the exit system call in the child process.
c) By using the wait system call in the parent process.
d) By using the exec system call to load a new program into the child process.
Answer: c) By using the wait system call in the parent process.
5. Lecture: Signals
**1. What are signals**

1. What are signals in the context of operating systems?


a) They are high-level programming constructs used for synchronization.
b) They are messages sent between processes to communicate with each other.
c) They are interrupts delivered to a process to notify events or exceptions.
d) They are mechanisms for memory management in multi-programming systems.

Answer: c) They are interrupts delivered to a process to notify events or exceptions.

2. How are signals identified in operating systems?


a) By their names (e.g., SIGINT, SIGSEGV).
b) By their process IDs (PIDs).
c) By their memory addresses.
d) By their priority levels.

Answer: a) By their names (e.g., SIGINT, SIGSEGV).

3. What is the primary purpose of signals in the context of process management?


a) To allocate CPU time to processes.
b) To manage process creation and termination.
c) To handle process synchronization and communication.
d) To notify processes about exceptional events and interruptions.

Answer: d) To notify processes about exceptional events and interruptions.

4. In Unix-like operating systems, how is a process notified when a signal is delivered to it?
a) The process receives a message through a special communication channel.
b) The process checks its mailbox for new signals.
c) The operating system sets a flag in the process control block.
d) The operating system transfers control to a signal handler function.

Answer: d) The operating system transfers control to a signal handler function.

5. Which of the following signals is commonly used to terminate a process gracefully?


a) SIGKILL
b) SIGSTOP
c) SIGINT
d) SIGTERM

Answer: d) SIGTERM

6. What is the default action of the SIGTERM signal in most operating systems?
a) Terminate the process without any cleanup.
b) Suspend the process temporarily.
c) Ignore the signal.
d) Execute a signal handler function.

Answer: a) Terminate the process without any cleanup.

7. Which signal is sent to a process when it attempts to access invalid memory?


a) SIGKILL
b) SIGSEGV
c) SIGTERM
d) SIGINT

Answer: b) SIGSEGV
8. What is the purpose of the SIGINT signal in Unix-like operating systems?
a) To interrupt the execution of a process.
b) To suspend a process temporarily.
c) To terminate a process immediately.
d) To handle arithmetic exceptions.

Answer: a) To interrupt the execution of a process.

9. In Unix-like operating systems, which command is used to send a signal to a process using its
process ID (PID)?
a) kill
b) signal
c) terminate
d) interrupt

Answer: a) kill

10. What is the purpose of the kill system call in Linux/Unix?


a) To terminate a process immediately.
b) To send a signal to a process.
c) To create a new process.
d) To execute a system command.

Answer: b) To send a signal to a process.

11. What happens if a process receives a SIGKILL signal?


a) The process is suspended temporarily.
b) The process is terminated immediately without any cleanup.
c) The process executes a signal handler function.
d) The process ignores the signal and continues its execution.

Answer: b) The process is terminated immediately without any cleanup.

12. In Unix-like operating systems, which signal is typically used to stop the execution of a process
temporarily?
a) SIGSTOP
b) SIGINT
c) SIGTERM
d) SIGKILL

Answer: a) SIGSTOP

**2. Generating and handling signals**

1. How can a signal be generated in an operating system?


a) By the user pressing specific key combinations (e.g., Ctrl+C).
b) By the operating system when a process completes its execution.
c) By a process using the kill system call to send a signal to another process.
d) By a process when it encounters a system call error.

Answer: c) By a process using the kill system call to send a signal to another process.

2. What is the purpose of the kill system call in Linux/Unix?


a) To terminate a process immediately.
b) To send a signal to a process.
c) To create a new process.
d) To execute a system command.

Answer: b) To send a signal to a process.


3. How can a process specify its desired action when a signal is received?
a) By using the sigaction system call to register a signal handler.
b) By changing the signal name in the process table entry.
c) By executing a special signal handling program.
d) By using the fork system call to create a new process.

Answer: a) By using the sigaction system call to register a signal handler.

4. When a signal is sent to a process, how does the operating system determine which action to take?
a) The operating system executes the default action for all signals.
b) The process explicitly specifies the action when it receives the signal.
c) The operating system checks the signal handling table of the process.
d) The signal handler function is invoked based on the signal number.

Answer: c) The operating system checks the signal handling table of the process.

5. What happens if a process does not handle a signal that is sent to it?
a) The process is terminated immediately.
b) The signal is sent to the parent process.
c) The signal is queued, and the process handles it later.
d) The process ignores the signal and continues its execution.

Answer: d) The process ignores the signal and continues its execution.

6. In the context of signal handling, what is the purpose of the sigaction system call?
a) To send a signal to another process.
b) To change the default action of a signal.
c) To specify the action to be taken when a signal is received.
d) To block a specific signal from being delivered to a process.

Answer: c) To specify the action to be taken when a signal is received.

7. How can a process temporarily block the delivery of a specific signal in Unix-like operating systems?
a) By changing the signal name in the process table entry.
b) By setting a flag in the process control block.
c) By executing a signal handler function.
d) By using the sigprocmask system call to set the signal mask.

Answer: d) By using the sigprocmask system call to set the signal mask.

8. Which signal is commonly used to terminate a process forcefully, without allowing it to perform any
cleanup tasks?
a) SIGKILL
b) SIGINT
c) SIGTERM
d) SIGSTOP

Answer: a) SIGKILL

9. What happens when a process receives a SIGINT signal?


a) The process is suspended temporarily.
b) The process is terminated immediately without any cleanup.

c) The process executes a signal handler function.


d) The process ignores the signal and continues its execution.

Answer: c) The process executes a signal handler function.


10. In Unix-like operating systems, how can a process send a signal to itself?
a) By using the fork system call.
b) By modifying the process control block.
c) By using the sigaction system call.
d) By using the kill system call with its own PID.

Answer: d) By using the kill system call with its own PID.

11. In Unix-like operating systems, how can a process send a signal to another process with a specific
PID?
a) By using the fork system call.
b) By modifying the process control block of the target process.
c) By using the sigaction system call.
d) By using the kill system call with the target PID.

Answer: d) By using the kill system call with the target PID.

12. Which signal is commonly used to suspend the execution of a process temporarily?
a) SIGKILL
b) SIGSTOP
c) SIGINT
d) SIGTERM

Answer: b) SIGSTOP
5. Threads

**1. What are threads; user and kernel threads; how threads are different from processes**

1. What is a thread in the context of operating systems?


a) It is a sequence of instructions that execute as part of a program.
b) It is a separate program with its own memory space.
c) It is a mechanism for inter-process communication.
d) It is an interrupt that transfers control to the operating system.

Answer: a) It is a sequence of instructions that execute as part of a program.

2. What is the primary advantage of using threads in a multi-threaded application?


a) Threads allow multiple processes to run concurrently.
b) Threads can run on different processors, improving performance.
c) Threads prevent deadlock and race conditions.
d) Threads are more secure than processes.

Answer: b) Threads can run on different processors, improving performance.

3. What is the main difference between a user-level thread and a kernel-level thread?
a) User-level threads are faster than kernel-level threads.
b) Kernel-level threads are managed by the operating system, while user-level threads are managed
by the application.
c) User-level threads use shared memory, while kernel-level threads use virtual memory.
d) Kernel-level threads are more scalable than user-level threads.

Answer: b) Kernel-level threads are managed by the operating system, while user-level threads are
managed by the application.

4. How are threads different from processes in terms of memory usage?


a) Threads share the same memory space, while processes have separate memory spaces.
b) Threads have their own copy of the program code, while processes share the program code.
c) Threads have their own file descriptors, while processes share file descriptors.
d) Threads use virtual memory, while processes use physical memory.

Answer: a) Threads share the same memory space, while processes have separate memory spaces.

5. Which of the following statements is true about thread creation compared to process creation?
a) Thread creation is slower than process creation.
b) Thread creation requires more system resources than process creation.
c) Thread creation is faster than process creation.
d) Thread creation requires a separate program.

Answer: c) Thread creation is faster than process creation.

6. In a multi-threaded application, what is the purpose of thread synchronization?


a) To create new threads.
b) To allow threads to execute independently without coordination.
c) To ensure that threads do not interfere with each other's execution.
d) To transfer control between threads.

Answer: c) To ensure that threads do not interfere with each other's execution.

7. What is the term used for a situation where multiple threads try to access and modify the same
shared resource simultaneously?
a) Thread deadlock
b) Thread race condition
c) Thread context switch
d) Thread priority inversion
Answer: b) Thread race condition

8. How do user-level threads typically achieve concurrency on a single-core processor?


a) By running in parallel on different cores.
b) By executing concurrently within the same process.
c) By using multi-threading libraries provided by the operating system.
d) By creating separate processes for each thread.

Answer: b) By executing concurrently within the same process.

9. In the context of multi-threading, what is context switching?


a) It is the process of creating a new thread.
b) It is the process of switching between different processes.
c) It is the process of switching between different threads.
d) It is the process of allocating memory for a thread.

Answer: c) It is the process of switching between different threads.

10. Which type of thread is more efficient in terms of context switching: user-level threads or kernel-
level threads?
a) User-level threads
b) Kernel-level threads
c) Both types have the same efficiency in context switching.
d) Efficiency depends on the number of threads.

Answer: b) Kernel-level threads

11. How do kernel-level threads improve system responsiveness compared to user-level threads?
a) Kernel-level threads have lower overhead in thread management.
b) Kernel-level threads are more lightweight than user-level threads.
c) Kernel-level threads can run concurrently on multiple processors.
d) Kernel-level threads are managed by the application, not the operating system.

Answer: c) Kernel-level threads can run concurrently on multiple processors.

12. Which of the following statements is true about the use of threads in a program?
a) Threads always execute sequentially and cannot overlap.
b) Threads are primarily used to create separate processes.
c) Threads can be used to achieve parallelism and improve performance.
d) Threads are used to enforce strict separation of concerns between different parts of a program.

Answer: c) Threads can be used to achieve parallelism and improve performance.

**2. Thread programming using pthread**

1. What is the full form of "

pthread" in pthread library used for thread programming?


a) Process Thread
b) POSIX Thread
c) Parallel Thread
d) Programmed Thread

Answer: b) POSIX Thread

2. In C/C++ programming, which header file should be included to use the pthread library?
a) <thread>
b) <pthread.h>
c) <sync>
d) <sync.h>

Answer: b) <pthread.h>

3. How is a new thread created using the pthread library in C/C++?


a) By calling the create_thread() function.
b) By calling the fork() function.
c) By calling the pthread_create() function.
d) By calling the start_thread() function.

Answer: c) By calling the pthread_create() function.

4. What is the signature of the pthread_create() function in C/C++?


a) void pthread_create(void* func, void* arg);
b) int pthread_create(pthread_t* thread, const pthread_attr_t* attr, void* (*start_routine) (void*),
void* arg);
c) int pthread_create(pthread_t thread, pthread_attr_t attr, void* (*start_routine) (void*), void* arg);
d) void* pthread_create(pthread_t* thread, void* (*start_routine) (void*), void* arg);

Answer: b) int pthread_create(pthread_t* thread, const pthread_attr_t* attr, void* (*start_routine)


(void*), void* arg);

5. How is a thread terminated using the pthread library?


a) By calling the stop_thread() function.
b) By returning from the thread function.
c) By calling the pthread_exit() function.
d) By calling the kill_thread() function.

Answer: c) By calling the pthread_exit() function.

6. How are thread-specific data (TSD) variables created and accessed in a multi-threaded program?
a) TSD variables are created automatically for each thread by the pthread library.
b) TSD variables are accessed using mutex locks.
c) TSD variables are accessed using global pointers.
d) TSD variables are created and accessed using special pthread functions.

Answer: d) TSD variables are created and accessed using special pthread functions.

7. In the context of pthread library, what is the purpose of the pthread_mutex_lock() function?
a) To create a new mutex object.
b) To unlock a mutex and allow access to a shared resource.
c) To block a thread until the specified mutex is unlocked.
d) To check the status of a mutex.

Answer: c) To block a thread until the specified mutex is unlocked.

8. Which type of thread synchronization mechanism is provided by the pthread library?


a) Conditional variables
b) Semaphores
c) Mutexes
d) Barriers

Answer: c) Mutexes

9. What is the purpose of the pthread_join() function in C/C++?


a) To wait for a thread to finish its execution.
b) To create a new thread and join it to the calling thread.
c) To detach a thread from the calling thread.
d) To create a new thread without joining it.
Answer: a) To wait for a thread to finish its execution.

10. How can a thread yield the CPU to another thread in a multi-threaded program?
a) By calling the pthread_sleep() function.
b) By calling the pthread_yield() function.
c) By calling the sleep() function.
d) By calling the yield() function.

Answer: b) By calling the pthread_yield() function.

11. Which of the following statements is true about thread cancellation in a multi-threaded program?
a) Thread cancellation is always immediate and cannot be controlled.
b) Thread cancellation is always deferred until the thread reaches a cancellation point.
c) Thread cancellation can only be initiated by the calling thread.
d) Thread cancellation can only be initiated by the operating system.

Answer: b) Thread cancellation is always deferred until the thread reaches a cancellation point.

12. How can a thread be canceled explicitly using the pthread library?
a) By calling the pthread_cancel() function with the thread ID.
b) By setting a cancel flag in the thread control block.
c) By calling the pthread_exit() function from another thread.
d) By calling the kill() function with the thread ID.

Answer: a) By calling the pthread_cancel() function with the thread ID.


7. Lecture: Memory management
**1. What are different types of memories; What is the need for Memory management**

1. Which of the following types of memory is directly accessible by the CPU for storing data and
instructions?
a) Secondary memory
b) Cache memory
c) Virtual memory
d) Tertiary memory

Answer: b) Cache memory

2. What is the primary purpose of memory management in an operating system?


a) To allocate resources for processes.
b) To manage disk space for file storage.
c) To optimize CPU utilization.
d) To ensure efficient and effective use of memory.

Answer: d) To ensure efficient and effective use of memory.

3. Which type of memory is non-volatile and used for long-term data storage even when the computer
is powered off?
a) RAM (Random Access Memory)
b) Cache memory
c) ROM (Read-Only Memory)
d) Virtual memory

Answer: c) ROM (Read-Only Memory)

4. What is the purpose of virtual memory in memory management?


a) To extend the available physical memory using secondary storage.
b) To provide faster access to frequently used data.
c) To store the program code of running processes.
d) To manage memory fragmentation.

Answer: a) To extend the available physical memory using secondary storage.

5. In a computer system, which type of memory is typically the fastest but also the smallest in capacity?
a) RAM (Random Access Memory)
b) Cache memory
c) Virtual memory
d) ROM (Read-Only Memory)

Answer: b) Cache memory

**2. Continuous and Dynamic allocation**

1. In continuous memory allocation, what is the main disadvantage of fixed partitioning?


a) It leads to excessive memory fragmentation.
b) It requires frequent compaction operations.
c) It limits the number of processes that can be loaded into memory.
d) It results in high overhead for memory management.

Answer: c) It limits the number of processes that can be loaded into memory.

2. Which memory allocation technique allows processes to be allocated memory in non-contiguous


blocks?
a) Fixed partitioning
b) Dynamic partitioning
c) Paging
d) Segmentation

Answer: d) Segmentation

3. What is the primary advantage of dynamic memory allocation over fixed memory allocation?
a) It reduces memory fragmentation.
b) It allows more efficient use of memory.
c) It improves CPU performance.
d) It eliminates the need for virtual memory.

Answer: b) It allows more efficient use of memory.

4. In dynamic memory allocation, what happens if a process requests more memory than the available
free space?
a) The operating system terminates the process.
b) The process is put on hold until memory becomes available.
c) The operating system compacts memory to create a larger free block.
d) The operating system allocates memory from the secondary storage.

Answer: b) The process is put on hold until memory becomes available.

5. Which memory allocation method requires maintaining a table to keep track of allocated and free
memory blocks?
a) Fixed partitioning
b) Dynamic partitioning
c) Paging
d) Segmentation

Answer: b) Dynamic partitioning

**3. First Fit, Best Fit, Worst Fit**

1. Which memory allocation algorithm searches for the first free memory block that is large enough to
accommodate a process?
a) First Fit
b) Best Fit
c) Worst Fit
d) Quick Fit

Answer: a) First Fit

2. What is the main advantage of the Best Fit memory allocation algorithm over the First Fit algorithm?
a) It reduces memory fragmentation.
b) It is faster in finding a free block for a process.
c) It allows larger processes to be allocated more efficiently.
d) It guarantees better overall memory utilization.

Answer: a) It reduces memory fragmentation.

3. In the context of memory allocation, which algorithm places a process in the largest available free
block?
a) First Fit
b) Best Fit
c) Worst Fit
d) Quick Fit

Answer: c) Worst Fit

4. How does the Best Fit memory allocation algorithm choose a free block for a process?
a) It selects the first free block that is large enough.
b) It selects the smallest free block that is large enough.
c) It selects the largest free block that is large enough.
d) It selects a free block randomly.

Answer: b) It selects the smallest free block that is large enough.

5. Which memory allocation algorithm may result in the most internal fragmentation?
a) First Fit
b) Best Fit
c) Worst Fit
d) Quick Fit

Answer: c) Worst Fit

**4. Compaction**

1. What is memory compaction in the context of memory management?


a) It is the process of rearranging memory blocks to eliminate fragmentation.
b

) It is the process of compressing memory contents to save space.


c) It is the process of defragmenting the hard disk.
d) It is the process of resizing memory partitions.

Answer: a) It is the process of rearranging memory blocks to eliminate fragmentation.

2. When does memory compaction typically occur in a system using dynamic memory allocation?
a) After every process terminates
b) At regular intervals
c) When there is not enough free memory to allocate a new process
d) When the system is rebooted

Answer: a) After every process terminates

3. What is the main benefit of memory compaction?


a) It reduces the overhead of memory management.
b) It increases the overall memory capacity of the system.
c) It reduces the time needed to perform context switches between processes.
d) It allows larger processes to be loaded into memory.

Answer: a) It reduces the overhead of memory management.

4. What is the potential drawback of memory compaction?


a) It can lead to an increase in external fragmentation.
b) It can slow down the performance of the system.
c) It can result in the loss of data stored in memory.
d) It can cause excessive wear and tear on memory modules.

Answer: b) It can slow down the performance of the system.

5. Which type of memory management technique is most likely to benefit from memory compaction?
a) Fixed partitioning
b) Dynamic partitioning
c) Paging
d) Segmentation

Answer: d) Segmentation

**5. Internal and External Fragmentation**


1. What is internal fragmentation in the context of memory management?
a) It is the unused memory space within a memory block allocated to a process.
b) It is the memory space between two adjacent memory blocks.
c) It is the unused memory space in the hard disk.
d) It is the process of rearranging memory blocks to eliminate fragmentation.

Answer: a) It is the unused memory space within a memory block allocated to a process.

2. Which memory allocation method is more prone to internal fragmentation?


a) First Fit
b) Best Fit
c) Worst Fit
d) Quick Fit

Answer: c) Worst Fit

3. What is external fragmentation in memory management?


a) It is the unused memory space within a memory block allocated to a process.
b) It is the memory space between two adjacent memory blocks.
c) It is the unused memory space in the hard disk.
d) It is the unused memory space scattered across the memory space.

Answer: d) It is the unused memory space scattered across the memory space.

4. Which memory allocation technique is more prone to external fragmentation?


a) Fixed partitioning
b) Dynamic partitioning
c) Paging
d) Segmentation

Answer: c) Paging

5. How can internal fragmentation be reduced in memory management?


a) By using a larger memory block size.
b) By using a smaller memory block size.
c) By using a more efficient memory allocation algorithm.
d) By using virtual memory.

Answer: b) By using a smaller memory block size.

**6. Segmentation – What is segmentation; Hardware requirement for segmentation; segmentation


table and its interpretation**

1. What is segmentation in the context of memory management?


a) It is the process of rearranging memory blocks to eliminate fragmentation.
b) It is the process of dividing memory into equal-sized partitions.
c) It is the process of dividing memory into variable-sized segments.
d) It is the process of compressing memory contents to save space.

Answer: c) It is the process of dividing memory into variable-sized segments.

2. What hardware is required to implement segmentation in memory management?


a) A memory controller
b) A paging unit
c) A segmentation table
d) A hard disk

Answer: c) A segmentation table


3. How is a segmentation table used in memory management?
a) It stores the contents of the memory segments.
b) It stores the mapping between logical addresses and physical addresses.
c) It stores the memory allocation status of each segment.
d) It stores the results of memory compaction.

Answer: b) It stores the mapping between logical addresses and physical addresses.

4. What is the primary benefit of segmentation compared to paging in memory management?


a) Segmentation reduces memory fragmentation.
b) Segmentation allows for faster context switches between processes.
c) Segmentation requires less hardware support.
d) Segmentation provides a more flexible memory allocation scheme.

Answer: d) Segmentation provides a more flexible memory allocation scheme.

5. How does segmentation help in managing variable-sized memory requirements of processes?


a) It divides memory into fixed-sized blocks for each process.
b) It allows processes to share memory segments.
c) It allocates memory to processes in contiguous blocks.
d) It allows memory to be allocated in variable-sized segments based on process needs.

Answer: d) It allows memory to be allocated in variable-sized segments based on process needs.

**7. Paging – What is paging; hardware required for paging; paging table; Translation look-aside
buffer**

1. What is paging in the context of memory management?


a) It is the process of dividing memory into equal-sized partitions.
b) It is the process of dividing memory into variable-sized segments.
c) It is the process of rearranging memory blocks to eliminate fragmentation.
d) It is the process of dividing memory into fixed-size blocks called pages.

Answer: d) It is the process of dividing memory into fixed-size blocks called pages.

2. Which hardware component is required to implement paging in memory management?


a) A memory controller
b) A segmentation table
c) A paging unit
d) A hard disk

Answer: c) A paging unit

3. What is the purpose of a paging table in memory management?


a) It stores the contents of the memory pages.
b) It stores the mapping between logical addresses and physical addresses.
c) It stores the memory allocation status of each page.
d) It stores the results of memory compaction.

Answer: b) It stores the mapping between logical addresses and physical addresses.

4. How is the Translation Look-aside Buffer (TLB) used in paging?


a) It stores the contents of the memory pages.
b) It stores the mapping between logical addresses and physical addresses.
c) It stores the memory allocation status of each page.
d) It stores the results of memory compaction.

Answer: b) It stores the mapping between logical addresses and physical addresses.

5. What is the main advantage of paging compared to segmentation in memory management?


a) Paging provides a more flexible memory allocation scheme.
b) Paging requires less hardware support.
c) Paging allows for faster context switches between processes.
d) Paging reduces memory fragmentation.

Answer: d) Paging reduces memory fragmentation.

**8. Concept of dirty bit**

1. What is the purpose of the dirty bit in memory management?


a) It indicates that a memory page has been recently accessed.
b) It indicates that a memory page contains outdated data.
c) It indicates that a memory page needs to be cleaned or updated before being evicted from memory.
d) It indicates that a memory page is corrupted and needs to be repaired.

Answer: c) It indicates that a memory page needs to be cleaned or updated before being evicted from
memory.

2. How is the dirty bit set for a memory page in a computer system?
a) It is set by the operating system when the page is loaded into memory.
b) It is set by the CPU when the page is accessed.
c) It is set by the user application when the page is modified.
d) It is set by the memory controller based on a predefined algorithm.

Answer: c) It is set by the user application when the page is modified.

3. What is the significance of the dirty bit during the process of page replacement in virtual memory?
a) It is used to determine the least recently used page for eviction.
b) It is used to determine the page with the lowest priority for eviction.
c) It is used to determine the page with the highest priority for eviction.
d) It is used to determine the most recently used page for eviction.

Answer: d) It is used to determine the most recently used page for eviction.

4. How does the dirty bit affect the page replacement policy in virtual memory?
a) Pages with the dirty bit set are more likely to be evicted.
b) Pages with the dirty bit set are less likely to be evicted.
c) Pages with the dirty bit set are evicted first.
d) Pages with the dirty bit set are never evicted.

Answer: a) Pages with the dirty bit set are more likely to be evicted.

**9. Shared pages and reentrant code**

1. In the context of memory management, what are shared pages?


a) Pages that are accessible by multiple processes.
b) Pages that contain shared libraries.
c) Pages that are shared between the CPU and memory.
d) Pages that are reserved for system processes.

Answer: a) Pages that are accessible by multiple processes.

2. What is the main advantage of using shared pages in a multi-process environment?


a) It reduces the overall memory consumption.
b) It simplifies the memory management process.
c) It allows processes to share data and code segments.
d) It eliminates the need for virtual memory.

Answer: c) It allows processes to share data and code segments.


3. What is reentrant code in memory management?
a) Code that can be executed by multiple processes simultaneously.
b) Code that can be executed by multiple threads simultaneously.
c) Code that can be executed by the CPU and memory simultaneously.
d) Code that can be executed by the operating system and user applications simultaneously.

Answer: b) Code that can be executed by multiple threads simultaneously.

4. What is the significance of reentrant code in a multi-threaded application?


a) It allows multiple threads to execute the same code without interfering with each other.
b) It ensures that only one thread can execute a specific code segment at a time.
c) It prevents threads from accessing shared data.
d) It reduces the memory footprint of the application.

Answer: a) It allows multiple threads to execute the same code without interfering with each other.

**10. Throttling**

1. What is throttling in the context of memory management?


a) It is the process of limiting the number of processes that can be loaded into memory.
b) It is the process of reducing the clock speed of the CPU to conserve power.
c) It is the process of compressing memory contents to save space.
d) It is the process of releasing memory resources to other processes.

Answer: a) It is the process of limiting the number of processes that can be loaded into memory.

2. What is the main reason for implementing throttling in memory management?


a) To prevent memory fragmentation.
b) To ensure fair memory allocation among processes.
c) To reduce the memory overhead of the operating system.
d) To improve CPU performance.

Answer: b) To ensure fair memory allocation among processes.

3. How does throttling affect the performance of a computer system?


a) It improves the overall system performance.
b) It has no significant impact on system performance.
c) It may slow down the system due to process limitations.
d) It may cause system crashes.

Answer: c) It may slow down the system due to process limitations.

4. What factors are typically considered when implementing throttling in memory management?
a) CPU speed and memory size
b) Process priority and memory usage
c) Disk space and network bandwidth
d) Graphics processing unit (GPU) capabilities

Answer: b) Process priority and memory usage.


8. Lecture: Virtual Memory
**1. What is virtual memory**

1. What is the primary purpose of virtual memory in a computer system?


a) To provide faster access to CPU registers.
b) To create a virtual environment for running multiple operating systems.
c) To extend the physical memory of the system using secondary storage.
d) To allocate memory for user applications.

Answer: c) To extend the physical memory of the system using secondary storage.

2. What is virtual memory?


a) Physical memory directly accessible by the CPU.
b) Memory used for storing temporary data.
c) Memory used for running virtual machines.
d) A combination of physical memory and secondary storage used as if it were RAM.

Answer: d) A combination of physical memory and secondary storage used as if it were RAM.

3. Which component of the operating system manages virtual memory?


a) Memory cache
b) Memory controller
c) Memory management unit (MMU)
d) Memory module

Answer: c) Memory management unit (MMU)

4. What happens when a program accesses a memory address that is not currently in physical memory?
a) The program crashes.
b) The operating system terminates the program.
c) A page fault occurs.
d) The program continues execution with an error message.

Answer: c) A page fault occurs.

5. Which type of memory is used to store the virtual memory mapping table in a computer system?
a) RAM (Random Access Memory)
b) Cache memory
c) ROM (Read-Only Memory)
d) Hard disk

Answer: a) RAM (Random Access Memory)

6. What is the purpose of the page table in virtual memory management?


a) To store the contents of the pages in secondary storage.
b) To map virtual addresses to physical addresses.
c) To store the operating system's code and data.
d) To allocate memory for running applications.

Answer: b) To map virtual addresses to physical addresses.

7. What is the benefit of using virtual memory in a computer system?


a) It allows faster access to physical memory.
b) It allows running larger programs than what can fit in physical memory.
c) It reduces the need for secondary storage.
d) It eliminates the need for paging and segmentation.

Answer: b) It allows running larger programs than what can fit in physical memory.
8. In a computer system with virtual memory, what is the role of the page table entry?
a) It contains the contents of a memory page.
b) It stores the virtual addresses of all processes.
c) It contains information about the location of a page in secondary storage.
d) It stores information about the mapping between virtual and physical addresses.

Answer: d) It stores information about the mapping between virtual and physical addresses.

9. Which memory management technique is used when the demand for memory exceeds the available
physical memory?
a) Paging
b) Segmentation
c) Swapping
d) Thrashing

Answer: c) Swapping

10. What is the size of a memory page in a computer system using virtual memory?
a) Fixed and equal to the size of the physical memory
b) Fixed and equal to the size of the secondary storage
c) Variable and determined by the operating system
d) Variable and determined by the size of the RAM

Answer: a) Fixed and equal to the size of the physical memory.

**2. Demand paging**

1. What is demand paging in virtual memory management?


a) A technique for reducing the demand for physical memory.
b) A technique for increasing the page size in virtual memory.
c) A technique for loading pages into memory only when they are needed.
d) A technique for allocating memory to processes on-demand.

Answer: c) A technique for loading pages into memory only when they are needed.

2. In demand paging, which pages are initially loaded into physical memory?
a) All pages of the process
b) Only the first page of the process
c) Only the last page of the process
d) None of the pages

Answer: d) None of the pages

3. When does a page fault occur in demand paging?


a) When a process terminates
b) When a page is read from secondary storage into physical memory
c) When a process is loaded into secondary storage
d) When a process requests a page that is not in physical memory

Answer: d) When a process requests a page that is not in physical memory

4. What happens when a page fault occurs in demand paging?


a) The process is terminated.
b) The operating system loads the required page from secondary storage into physical memory.
c) The process is put on hold until physical memory becomes available.
d) The process continues execution with an error message.

Answer: b) The operating system loads the required page from secondary storage into physical memory.

5. Which page replacement algorithm is commonly used with demand paging?


a) First-In-First-Out (FIFO)
b) Least Recently Used (LRU)
c) Optimal Page Replacement
d) Random Page Replacement

Answer: b) Least Recently Used (LRU)

6. What is the advantage of demand paging over pre-loading all pages of a process into physical
memory?
a) It reduces memory overhead.
b) It eliminates the need for page replacement algorithms.
c) It allows for faster context switches between processes.
d) It

reduces the likelihood of page faults.

Answer: a) It reduces memory overhead.

7. In demand paging, what is the role of the page table entry for a page that is not in physical memory?
a) It contains the contents of the page.
b) It stores the virtual address of the page in secondary storage.
c) It stores the physical address of the page in secondary storage.
d) It stores information about the location of the page in physical memory.

Answer: c) It stores the physical address of the page in secondary storage.

8. How does demand paging affect the overall performance of a computer system?
a) It improves performance by reducing memory access time.
b) It has no significant impact on performance.
c) It may slow down performance due to page faults and loading from secondary storage.
d) It improves performance by increasing the size of the page file.

Answer: c) It may slow down performance due to page faults and loading from secondary storage.

**3. Page faults**

1. What is a page fault in the context of virtual memory management?


a) A process requesting more memory than the operating system can provide.
b) A process accessing a page that is not currently in physical memory.
c) A page containing errors and needing to be replaced.
d) A process being terminated due to a memory-related error.

Answer: b) A process accessing a page that is not currently in physical memory.

2. What typically causes a page fault to occur in a computer system using virtual memory?
a) The CPU running at full capacity.
b) A user application exceeding its allocated memory space.
c) A page being evicted from physical memory.
d) A process accessing a page not present in physical memory.

Answer: d) A process accessing a page not present in physical memory.

3. When a page fault occurs, what action does the operating system take?
a) It terminates the process that caused the page fault.
b) It allocates a new page to the process from secondary storage.
c) It swaps out a page from another process to make room for the requested page.
d) It loads the required page from secondary storage into physical memory.

Answer: d) It loads the required page from secondary storage into physical memory.
4. What is the typical response time for handling a page fault in a computer system?
a) A few microseconds
b) A few milliseconds
c) A few seconds
d) A few minutes

Answer: b) A few milliseconds

5. How can a high rate of page faults affect the performance of a computer system?
a) It leads to faster execution of processes.
b) It may cause the system to become unresponsive and slow down.
c) It reduces the need for page replacement algorithms.
d) It improves the cache hit rate.

Answer: b) It may cause the system to become unresponsive and slow down.

6. What is the primary cause of excessive page faults in a computer system using virtual memory?
a) Insufficient physical memory to hold all active pages of processes.
b) Page replacement algorithms being too aggressive.
c) The excessive use of shared memory.
d) Hardware failure in the memory module.

Answer: a) Insufficient physical memory to hold all active pages of processes.

7. How can the rate of page faults be reduced in a computer system?


a) By increasing the page size in virtual memory.
b) By decreasing the amount of secondary storage available.
c) By using a more aggressive page replacement algorithm.
d) By reducing the number of running processes.

Answer: a) By increasing the page size in virtual memory.

8. What is the significance of the page fault rate in performance monitoring of a computer system?
a) It indicates the average time taken to handle a page fault.
b) It reflects the efficiency of the page replacement algorithm.
c) It measures the rate at which processes are being terminated.
d) It is used to calculate the amount of physical memory in use.

Answer: b) It reflects the efficiency of the page replacement algorithm.

**4. Page replacement algorithms**

1. What is the main goal of page replacement algorithms in virtual memory management?
a) To increase the page size in virtual memory.
b) To reduce the number of page faults in the system.
c) To allocate memory for running processes.
d) To compress memory contents to save space.

Answer: b) To reduce the number of page faults in the system.

2. Which page replacement algorithm uses the principle of "FIFO" (First-In-First-Out)?


a) Optimal Page Replacement
b) Least Recently Used (LRU)
c) First-In-First-Out (FIFO)
d) Random Page Replacement

Answer: c) First-In-First-Out (FIFO)

3. How does the FIFO page replacement algorithm work?


a) It replaces the page that has been in memory the longest.
b) It replaces the page that has been accessed the least.
c) It replaces the page that has the highest priority.
d) It replaces a random page from memory.

Answer: a) It replaces the page that has been in memory the longest.

4. Which page replacement algorithm is considered the most efficient in terms of minimizing the
number of page faults?
a) Optimal Page Replacement
b) Least Recently Used (LRU)
c) First-In-First-Out (FIFO)
d) Random Page Replacement

Answer: a) Optimal Page Replacement

5. How does the Optimal Page Replacement algorithm make its replacement decision?
a) It replaces the page that has been in memory the longest.
b) It replaces the page that will not be used for the longest period.
c) It replaces a random page from memory.
d) It replaces the page that has been accessed the most.

Answer: b) It replaces the page that will not be used for the longest period.

6. What is the drawback of using the Optimal Page Replacement algorithm in real systems?
a) It is computationally expensive and may not be practical.
b) It does not effectively reduce the number of page faults.
c) It requires a large page table to store information about future page accesses.
d) It is only suitable for systems with a small number of processes.

Answer: a) It is computationally expensive and may not be practical.

7. Which page replacement algorithm approximates the optimal algorithm by tracking the least recently
used pages?
a) Least Recently Used (LRU)
b) First-In-First-Out (FIFO)
c) Optimal Page Replacement
d) Random Page Replacement

Answer: a) Least Recently Used (LRU)

8. How does the Least Recently Used (LRU) page replacement algorithm work?
a) It replaces the page that has been in memory the longest.
b) It replaces the page that has been accessed the most recently.
c) It replaces a random page from memory.
d) It replaces the page that has the highest priority.

Answer: b) It replaces the page that has been accessed the most recently.
9. Lecture: Deadlock

**1. Necessary conditions of deadlock**

1. Which of the following is a necessary condition for deadlock to occur in a system?


a) Mutual exclusion
b) Resource preemption
c) Hold and wait
d) Circular wait

Answer: c) Hold and wait

2. In the context of deadlock, what does the "mutual exclusion" condition mean?
a) A process must wait for the release of a resource held by another process.
b) A resource can be accessed by multiple processes simultaneously.
c) A process can access multiple resources at the same time.
d) A resource can be preempted and reallocated to another process.

Answer: b) A resource can be accessed by multiple processes simultaneously.

3. Which condition ensures that a process must wait for a resource that is held by another process,
leading to deadlock?
a) Mutual exclusion
b) Resource preemption
c) Hold and wait
d) Circular wait

Answer: c) Hold and wait

4. What is the "circular wait" condition in deadlock?


a) A process holds multiple resources at the same time.
b) Resources are allocated to processes in a circular fashion.
c) A process waits for a resource that is held by another process in a circular chain.
d) Resources are preempted and reallocated in a circular manner.

Answer: c) A process waits for a resource that is held by another process in a circular chain.

5. Which of the following is NOT a necessary condition for deadlock?


a) Mutual exclusion
b) Resource preemption
c) Hold and wait
d) Absence of resource waiting

Answer: b) Resource preemption

6. If a system satisfies all the necessary conditions for deadlock, will deadlock always occur?
a) Yes, deadlock is unavoidable in such a system.
b) No, deadlock can still be avoided by careful resource allocation and scheduling.
c) Yes, but deadlock can be resolved automatically by the operating system.
d) No, deadlock can only occur if the system is in an unstable state.

Answer: b) No, deadlock can still be avoided by careful resource allocation and scheduling.

7. Which of the following conditions ensures that a process releases all its resources before requesting
new ones?
a) Mutual exclusion
b) Resource preemption
c) Hold and wait
d) Circular wait
Answer: d) Circular wait

8. Which of the following deadlock conditions is most challenging to prevent in a system?


a) Mutual exclusion
b) Resource preemption
c) Hold and wait
d) Circular wait

Answer: c) Hold and wait

**2. Deadlock prevention and avoidance**

1. What is deadlock prevention in the context of operating systems?


a) Identifying and terminating processes that are deadlocked.
b) Restricting access to resources in such a way that deadlock cannot occur.
c) Allowing deadlock to occur and then resolving it automatically.
d) Letting processes run independently and not intervening to prevent deadlock.

Answer: b) Restricting access to resources in such a way that deadlock cannot occur.

2. Which technique ensures that the system will never enter a deadlocked state by carefully allocating
resources to processes?
a) Deadlock avoidance
b) Deadlock detection
c) Deadlock recovery
d) Deadlock prevention

Answer: d) Deadlock prevention

3. What is deadlock avoidance in the context of operating systems?


a) Letting processes run independently and resolving deadlock if it occurs.
b) Detecting and terminating deadlocked processes automatically.
c) Identifying deadlock-prone situations and avoiding them by careful resource allocation.
d) Ensuring that the system will never enter a deadlocked state.

Answer: c) Identifying deadlock-prone situations and avoiding them by careful resource allocation.

4. Which resource allocation technique uses a resource allocation graph to avoid deadlock?
a) Deadlock avoidance
b) Deadlock detection
c) Deadlock recovery
d) Deadlock prevention

Answer: a) Deadlock avoidance

5. In the context of deadlock avoidance, what does a resource allocation graph represent?
a) Processes and their resource requests.
b) Processes and their resource releases.
c) Processes and their dependencies.
d) Processes and their priorities.

Answer: a) Processes and their resource requests.

6. What is the main disadvantage of deadlock avoidance?


a) It requires a complex deadlock detection algorithm.
b) It may lead to inefficient resource utilization.
c) It cannot prevent all possible deadlocks.
d) It can cause processes to be terminated unnecessarily.
Answer: b) It may lead to inefficient resource utilization.

7. Which of the following statements is true about deadlock avoidance?


a) Deadlock avoidance guarantees that deadlock will never occur.
b) Deadlock avoidance uses a centralized algorithm to detect deadlocks.
c) Deadlock avoidance requires the use of a special type of mutex.
d) Deadlock avoidance avoids the hold and wait condition.

Answer: d) Deadlock avoidance avoids the hold and wait condition.

8. What is the primary advantage of deadlock prevention over deadlock avoidance?


a) Deadlock prevention guarantees that deadlock will never occur.
b) Deadlock prevention is more efficient in terms of resource utilization.
c) Deadlock prevention does not require a complex algorithm.
d) Deadlock prevention can handle a higher number of processes.

Answer: b) Deadlock prevention is more efficient in terms of resource utilization.

**3. Semaphore**

1. What is a semaphore in the context of concurrent programming?


a) A communication mechanism between processes.
b) A synchronization primitive used to control access to shared resources.
c) A type of process scheduling algorithm.
d) A mechanism for handling page faults in virtual memory.

Answer: b) A synchronization primitive used to control access to shared resources.

2. What is the purpose of a semaphore in concurrent programming?


a) To create new processes in a multi-core system.
b) To allocate memory for running processes.
c) To signal the completion of a task.
d) To prevent multiple processes from accessing a shared resource simultaneously.

Answer: d) To prevent multiple processes from accessing a shared resource simultaneously.

3. How does a semaphore work to control access to a shared resource?


a) It allocates a fixed amount of memory to each process.
b) It assigns a priority level to each process.
c) It maintains a count of available resource instances and blocks processes if the count reaches zero.
d) It performs context switches between processes.

Answer: c) It maintains a count of available resource instances and blocks processes if the count
reaches zero.

4. Which operation(s) can be performed on a semaphore?


a) Increment (V) and Decrement (P)
b) Add and Subtract
c) Multiply and Divide
d) Read and Write

Answer: a) Increment (V) and Decrement (P)

5. In the context of semaphores, what does the "V" operation do?


a) Increments the semaphore count and signals waiting processes.
b) Decrements the semaphore count and blocks the calling process if the count is negative.
c) Blocks the calling process until the semaphore count becomes positive.

d) Increments the semaphore count and blocks the calling process if the count is zero.
Answer: a) Increments the semaphore count and signals waiting processes.

6. What is a binary semaphore?


a) A semaphore that can only take binary values (0 or 1).
b) A semaphore that can only be used with two processes.
c) A semaphore that is used for binary arithmetic operations.
d) A semaphore that has two mutually exclusive operations.

Answer: a) A semaphore that can only take binary values (0 or 1).

7. Which operation is used to decrement a semaphore and potentially block the calling process?
a) V operation
b) Increment operation
c) P operation
d) Signal operation

Answer: c) P operation

8. How do semaphores help prevent race conditions in concurrent programs?


a) They prevent processes from executing in parallel.
b) They ensure that processes are scheduled fairly.
c) They synchronize access to shared resources.
d) They allocate a fixed amount of CPU time to each process.

Answer: c) They synchronize access to shared resources.

**4. Mutex**

1. What is a mutex in concurrent programming?


a) A communication mechanism between processes.
b) A synchronization primitive used to protect critical sections of code.
c) A type of process scheduling algorithm.
d) A mechanism for handling page faults in virtual memory.

Answer: b) A synchronization primitive used to protect critical sections of code.

2. What is the purpose of a mutex in concurrent programming?


a) To create new processes in a multi-core system.
b) To allocate memory for running processes.
c) To signal the completion of a task.
d) To prevent multiple processes from simultaneously executing a critical section.

Answer: d) To prevent multiple processes from simultaneously executing a critical section.

3. How does a mutex work to protect a critical section of code?


a) It allocates a fixed amount of memory to each process.
b) It assigns a priority level to each process.
c) It allows multiple processes to access the critical section simultaneously.
d) It grants exclusive access to the critical section to one process at a time.

Answer: d) It grants exclusive access to the critical section to one process at a time.

4. Which operation(s) can be performed on a mutex?


a) Lock and Unlock
b) Add and Subtract
c) Multiply and Divide
d) Read and Write

Answer: a) Lock and Unlock


5. In the context of mutex, what does the "Lock" operation do?
a) Grants exclusive access to the critical section to the calling process.
b) Releases the lock and allows multiple processes to access the critical section.
c) Blocks the calling process until the mutex is available.
d) Unblocks all waiting processes.

Answer: a) Grants exclusive access to the critical section to the calling process.

6. What is the purpose of using a mutex to protect shared resources in concurrent programming?
a) To ensure that all processes execute in parallel.
b) To increase the efficiency of the system by allowing multiple processes to access shared resources
simultaneously.
c) To prevent race conditions and data corruption when multiple processes access shared resources.
d) To allocate a fixed amount of CPU time to each process.

Answer: c) To prevent race conditions and data corruption when multiple processes access shared
resources.

7. Which operation is used to release a mutex and allow other processes to access the critical section?
a) Lock operation
b) Lock and Unlock operation
c) Unlock operation
d) Unlock and Lock operation

Answer: c) Unlock operation

8. How does a mutex help ensure mutual exclusion in concurrent programs?


a) By preventing processes from executing in parallel.
b) By ensuring that processes are scheduled fairly.
c) By providing a binary semaphore for critical sections.
d) By granting exclusive access to critical sections to one process at a time.

Answer: d) By granting exclusive access to critical sections to one process at a time.

**5. Producer-consumer problem**

1. What is the producer-consumer problem in concurrent programming?


a) A problem related to process scheduling.
b) A synchronization problem involving the sharing of a bounded buffer by multiple processes.
c) A deadlock prevention technique.
d) A problem related to virtual memory management.

Answer: b) A synchronization problem involving the sharing of a bounded buffer by multiple processes.

2. In the producer-consumer problem, what is the role of the producer process?


a) It consumes items from the buffer.
b) It manages the synchronization of the buffer.
c) It produces items and adds them to the buffer.
d) It releases resources used by the consumer.

Answer: c) It produces items and adds them to the buffer.

3. In the producer-consumer problem, what is the role of the consumer process?


a) It consumes items from the buffer.
b) It manages the synchronization of the buffer.
c) It produces items and adds them to the buffer.
d) It releases resources used by the producer.

Answer: a) It consumes items from the buffer.


4. What is the main challenge in solving the producer-consumer problem?
a) Ensuring that the producer process does not produce items too quickly.
b) Ensuring that the consumer process does not consume items too quickly.
c) Synchronizing the access to the shared buffer to avoid race conditions.
d) Allocating enough memory for the buffer.

Answer: c) Synchronizing the access to the shared buffer to avoid race conditions.

5. Which synchronization primitive is commonly used to solve the producer-consumer problem?


a) Semaphore
b) Mutex
c) Thread
d) Process

Answer: a) Semaphore

6. How does a semaphore help in solving the producer-consumer problem?


a) It controls the number of producer and consumer processes.
b) It synchronizes the access to the shared buffer by allowing only one process to access it at a time.
c) It allocates memory for the shared buffer.
d) It prevents processes from accessing the shared buffer.

Answer: b) It synchronizes the access to the shared buffer by allowing only one process to access it at a
time.

7. In the context of the producer-consumer problem, what does the "empty" semaphore represent?
a) The number of empty slots in the buffer where items can be produced.
b) The number of items currently present in the buffer.
c) The number of producer processes waiting to add items to the buffer.
d) The number of consumer processes waiting to consume items from the buffer.
Answer: a) The number of empty slots in the buffer where items can be produced.

8. How does the producer-consumer problem illustrate the importance of synchronization in concurrent
programming?
a) It demonstrates the need for preemptive scheduling algorithms.
b) It shows how processes can be created and terminated dynamically.
c) It highlights the challenges of resource allocation.
d) It exemplifies the need to coordinate the execution of multiple processes.
Answer: d) It exemplifies the need to coordinate the execution of multiple processes.

**6. Deadlock vs. Starvation**

1. What is deadlock in the context of operating

systems?
a) A situation where a process cannot proceed because it is waiting for a resource held by another
process.
b) A situation where two or more processes are blocked, each waiting for the other to release a
resource.
c) A situation where a process consumes all available resources and prevents other processes from
executing.
d) A situation where a process is terminated prematurely.

Answer: b) A situation where two or more processes are blocked, each waiting for the other to release a
resource.

2. What is starvation in the context of operating systems?


a) A situation where a process cannot proceed because it is waiting for a resource held by another
process.
b) A situation where two or more processes are blocked, each waiting for the other to release a
resource.
c) A situation where a process consumes all available resources and prevents other processes from
executing.
d) A situation where a process is unable to obtain the resources it needs to make progress.

Answer: d) A situation where a process is unable to obtain the resources it needs to make progress.

3. How does deadlock differ from starvation?


a) Deadlock involves processes waiting for resources, while starvation involves a process being
unable to obtain resources.
b) Deadlock occurs when a process consumes all available resources, while starvation occurs when
processes block each other.
c) Deadlock can be resolved by the operating system, while starvation cannot.
d) Deadlock results in the termination of processes, while starvation does not.

Answer: a) Deadlock involves processes waiting for resources, while starvation involves a process
being unable to obtain resources.

4. Which of the following statements is true about deadlock and starvation?


a) Deadlock and starvation are the same concepts and can be used interchangeably.
b) Deadlock and starvation are caused by the same set of necessary conditions.
c) Deadlock can be resolved by increasing resource allocation, while starvation can be resolved by
resource preemption.
d) Deadlock is more severe than starvation as it may lead to system-wide halt.

Answer: c) Deadlock can be resolved by increasing resource allocation, while starvation can be
resolved by resource preemption.

5. In the context of deadlock, what is the role of resource preemption?


a) It prevents processes from accessing shared resources.
b) It allows a process to hold a resource indefinitely.
c) It forcibly removes a resource from a process to resolve deadlock.
d) It increases the priority of a process to resolve deadlock.

Answer: c) It forcibly removes a resource from a process to resolve deadlock.

6. How can an operating system handle the issue of starvation in resource allocation?
a) By terminating processes that cause starvation.
b) By granting resources based on the first-come-first-serve principle.
c) By increasing the priority of processes that have been waiting for a long time.
d) By allocating resources fairly to all processes.

Answer: c) By increasing the priority of processes that have been waiting for a long time.

7. What are the necessary conditions for deadlock to occur?


a) Mutual exclusion, resource preemption, hold and wait, and circular wait.
b) Mutual exclusion, resource preemption, hold and wait, and absence of resource waiting.
c) Absence of resource waiting, resource preemption, hold and wait, and circular wait.
d) Absence of resource waiting, resource preemption, hold and wait, and absence of mutual exclusion.

Answer: b) Mutual exclusion, resource preemption, hold and wait, and absence of resource waiting.

8. How can deadlock and starvation impact the performance of an operating system?
a) Deadlock and starvation lead to system crashes.
b) Deadlock and starvation increase the overall efficiency of the system.
c) Deadlock can halt the entire system, while starvation causes low resource utilization.
d) Deadlock and starvation can be resolved by increasing the number of available resources.

Answer: c) Deadlock can halt the entire system, while starvation causes low resource utilization.
10. Lecture: Inter-process communication
11.
**1. Message queues**

1. What is a message queue in inter-process communication (IPC)?


a) A communication channel between the CPU and memory.
b) A mechanism for sharing files between processes.
c) A data structure for storing messages that can be accessed by multiple processes.
d) A technique for transferring data between threads.

Answer: c) A data structure for storing messages that can be accessed by multiple processes.

2. How do processes communicate using message queues?


a) By directly reading and writing to each other's memory space.
b) By exchanging messages through a centralized queue.
c) By using network sockets for communication.
d) By sharing file descriptors.

Answer: b) By exchanging messages through a centralized queue.

3. Which of the following is a characteristic of message queues?


a) They only support one-to-one communication between processes.
b) They are limited to a single process.
c) They can be used for both one-to-one and one-to-many communication.
d) They are not suitable for real-time systems.

Answer: c) They can be used for both one-to-one and one-to-many communication.

4. In message queuing, what happens if a process tries to read from an empty queue?
a) The process waits until a message is available in the queue.
b) The process receives an error message.
c) The queue automatically creates a new message for the process to read.
d) The process sends a signal to other processes.

Answer: a) The process waits until a message is available in the queue.

5. What is the role of a message queue in inter-process communication?


a) To control the execution of processes in a multi-core system.
b) To buffer data transmitted between processes.
c) To synchronize the access to shared resources.
d) To allocate memory for running processes.

Answer: b) To buffer data transmitted between processes.

6. Which IPC mechanism is best suited for exchanging large volumes of data between processes?
a) Shared memory
b) Message queues
c) Pipes
d) FIFO

Answer: b) Message queues

7. How do message queues ensure that messages are processed in the order they are received?
a) By assigning priority levels to processes.
b) By using round-robin scheduling.
c) By using first-in-first-out (FIFO) order.
d) By allowing processes to choose the order in which they process messages.

Answer: c) By using first-in-first-out (FIFO) order.


8. What is the advantage of using message queues for inter-process communication?
a) They require less memory compared to other IPC mechanisms.
b) They are faster than shared memory for communication between processes.
c) They provide a reliable way to exchange data between processes.
d) They do not require synchronization between processes.

Answer: c) They provide a reliable way to exchange data between processes.

9. How are messages identified in a message queue?


a) Messages are identified by their content.
b) Messages are identified by their size.
c) Messages are identified by a unique identifier assigned by the sender.
d) Messages are identified by their position in the queue.

Answer: c) Messages are identified by a unique identifier assigned by the sender.

10. Which IPC mechanism allows processes to communicate by writing and reading from a common
buffer?
a) Message queues
b) Shared memory
c) Pipes
d) FIFO

Answer: b) Shared memory

**2. Shared memory**

1. What is shared memory in inter-process communication (IPC)?


a) A communication channel between the CPU and memory.
b) A mechanism for sharing files between processes.
c) A region of memory that can be accessed by multiple processes.
d) A technique for transferring data between threads.

Answer: c) A region of memory that can be accessed by multiple processes.

2. How do processes communicate using shared memory?


a) By directly reading and writing to each other's memory space.
b) By exchanging messages through a centralized queue.
c) By using network sockets for communication.
d) By sharing file descriptors.

Answer: a) By directly reading and writing to each other's memory space.

3. Which of the following is a characteristic of shared memory?


a) It only supports one-to-one communication between processes.
b) It is limited to a single process.
c) It can be used for both one-to-one and one-to-many communication.
d) It is not suitable for real-time systems.

Answer: c) It can be used for both one-to-one and one-to-many communication.

4. In shared memory communication, what happens if multiple processes try to access the shared
memory simultaneously?
a) The operating system assigns priority to processes based on their IDs.
b) The processes enter into a deadlock and block each other.
c) The operating system schedules processes to access the shared memory one at a time.
d) The processes use semaphores to synchronize access to the shared memory.

Answer: d) The processes use semaphores to synchronize access to the shared memory.
5. What is the role of shared memory in inter-process communication?
a) To control the execution of processes in a multi-core system.
b) To buffer data transmitted between processes.
c) To synchronize the access to shared resources.
d) To allocate memory for running processes.

Answer: c) To synchronize the access to shared resources.

6. Which IPC mechanism is best suited for high-performance data sharing between processes?
a) Message queues
b) Shared memory
c) Pipes
d) FIFO

Answer: b) Shared memory

7. How does shared memory handle data consistency between processes?


a) It relies on hardware mechanisms to ensure data consistency.
b) It uses software-based locking mechanisms to ensure data consistency.
c) It creates a copy of the data for each process to ensure data consistency.
d) It does not handle data consistency between processes.

Answer: b) It uses software-based locking mechanisms to ensure data consistency.

8. What is the advantage of using shared memory for inter-process communication?


a) It requires less memory compared to other IPC mechanisms.
b) It provides a faster way to exchange data between processes.
c) It provides a reliable way to exchange data between processes.
d) It allows processes to communicate without the need for synchronization.

Answer: b) It provides a faster way to exchange data between processes.

9. How are processes prevented from overwriting each other's data in shared memory?
a) By using message identifiers to differentiate between messages from different processes.
b) By using semaphores to control access to shared memory.
c) By allocating separate memory regions for each process.
d) By using message queues to buffer data.

Answer: b) By using semaphores to control access to shared memory.

10. Which IPC mechanism allows processes to communicate by writing and reading from a common
buffer?
a) Message queues
b) Shared memory
c) Pipes
d) FIFO

Answer: b) Shared memory

**3. Pipes**

1. What is a pipe in inter-process communication (IPC)?


a) A communication channel between the CPU and memory.
b) A mechanism for sharing files

between processes.
c) A one-way communication channel between two related processes.
d) A technique for transferring data between threads.
Answer: c) A one-way communication channel between two related processes.

2. How do processes communicate using pipes?


a) By directly reading and writing to each other's memory space.
b) By exchanging messages through a centralized queue.
c) By using network sockets for communication.
d) By sharing file descriptors.

Answer: c) By using network sockets for communication.

3. Which of the following is a characteristic of pipes?


a) Pipes can be used for both one-to-one and one-to-many communication.
b) Pipes can only be used for one-to-one communication between processes.
c) Pipes are limited to a single process.
d) Pipes are suitable for real-time systems.

Answer: b) Pipes can only be used for one-to-one communication between processes.

4. In pipe communication, which process is responsible for creating the pipe?


a) The parent process.
b) The child process.
c) Both the parent and child processes together.
d) An external system service.

Answer: c) Both the parent and child processes together.

5. What is the role of pipes in inter-process communication?


a) To control the execution of processes in a multi-core system.
b) To buffer data transmitted between processes.
c) To synchronize the access to shared resources.
d) To provide a unidirectional communication channel between processes.

Answer: d) To provide a unidirectional communication channel between processes.

6. Which IPC mechanism is best suited for simple communication between two related processes?
a) Message queues
b) Shared memory
c) Pipes
d) FIFO

Answer: c) Pipes

7. How does pipe communication handle data flow between processes?


a) Data is transmitted bidirectionally between processes.
b) Data is transmitted in a first-in-first-out (FIFO) order.
c) Data is transmitted in random order.
d) Data is transmitted in parallel to multiple processes.

Answer: b) Data is transmitted in a first-in-first-out (FIFO) order.

8. What is the advantage of using pipes for inter-process communication?


a) Pipes allow bidirectional communication between processes.
b) Pipes provide a reliable way to exchange data between processes.
c) Pipes are more efficient than other IPC mechanisms.
d) Pipes can be used for communication between unrelated processes.

Answer: b) Pipes provide a reliable way to exchange data between processes.

9. How are processes synchronized when using pipes for communication?


a) By using message identifiers to differentiate between messages from different processes.
b) By using semaphores to control access to the pipe.
c) By allocating separate memory regions for each process.
d) By using message queues to buffer data.

Answer: b) By using semaphores to control access to the pipe.

10. Which IPC mechanism allows processes to communicate by writing and reading from a common
buffer?
a) Message queues
b) Shared memory
c) Pipes
d) FIFO

Answer: c) Pipes

**4. FIFO**

1. What is a FIFO (First-In-First-Out) in inter-process communication (IPC)?


a) A communication channel between the CPU and memory.
b) A mechanism for sharing files between processes.
c) A one-way communication channel between two unrelated processes.
d) A technique for transferring data between threads.

Answer: c) A one-way communication channel between two unrelated processes.

2. How do processes communicate using FIFOs?


a) By directly reading and writing to each other's memory space.
b) By exchanging messages through a centralized queue.
c) By using network sockets for communication.
d) By using file descriptors to read and write from a common buffer.

Answer: d) By using file descriptors to read and write from a common buffer.

3. Which of the following is a characteristic of FIFOs?


a) FIFOs can be used for both one-to-one and one-to-many communication between processes.
b) FIFOs can only be used for one-to-one communication between processes.
c) FIFOs are limited to a single process.
d) FIFOs are suitable for real-time systems.

Answer: b) FIFOs can only be used for one-to-one communication between processes.

4. In FIFO communication, which process is responsible for creating the FIFO?


a) The parent process.
b) The child process.
c) Both the parent and child processes together.
d) An external system service.

Answer: c) Both the parent and child processes together.

5. What is the role of FIFOs in inter-process communication?


a) To control the execution of processes in a multi-core system.
b) To buffer data transmitted between processes.
c) To synchronize the access to shared resources.
d) To provide a unidirectional communication channel between unrelated processes.

Answer: d) To provide a unidirectional communication channel between unrelated processes.

6. Which IPC mechanism is best suited for communication between unrelated processes?
a) Message queues
b) Shared memory
c) Pipes
d) FIFO

Answer: d) FIFO

7. How does FIFO communication handle data flow between processes?


a) Data is transmitted bidirectionally between processes.
b) Data is transmitted in a first-in-first-out (FIFO) order.
c) Data is transmitted in random order.
d) Data is transmitted in parallel to multiple processes.

Answer: b) Data is transmitted in a first-in-first-out (FIFO) order.

8. What is the advantage of using FIFOs for inter-process communication?


a) FIFOs allow bidirectional communication between processes.
b) FIFOs provide a reliable way to exchange data between processes.
c) FIFOs are more efficient than other IPC mechanisms.
d) FIFOs can be used for communication between related processes.

Answer: b) FIFOs provide a reliable way to exchange data between processes.

9. How are processes synchronized when using FIFOs for communication?


a) By using message identifiers to differentiate between messages from different processes.
b) By using semaphores to control access to the FIFO.
c) By allocating separate memory regions for each process.
d) By using message queues to buffer data.

Answer: b) By using semaphores to control access to the FIFO.

10. Which IPC mechanism allows processes to communicate by writing and reading from a common
buffer?
a) Message queues
b) Shared memory
c) Pipes
d) FIFO

Answer: d) FIFO

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