Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Tests  >  Test: Process- 2 - Computer Science Engineering (CSE) MCQ

Test: Process- 2 - Computer Science Engineering (CSE) MCQ


Test Description

20 Questions MCQ Test - Test: Process- 2

Test: Process- 2 for Computer Science Engineering (CSE) 2024 is part of Computer Science Engineering (CSE) preparation. The Test: Process- 2 questions and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus.The Test: Process- 2 MCQs are made for Computer Science Engineering (CSE) 2024 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests for Test: Process- 2 below.
Solutions of Test: Process- 2 questions in English are available as part of our course for Computer Science Engineering (CSE) & Test: Process- 2 solutions in Hindi for Computer Science Engineering (CSE) course. Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free. Attempt Test: Process- 2 | 20 questions in 60 minutes | Mock test for Computer Science Engineering (CSE) preparation | Free important questions MCQ to study for Computer Science Engineering (CSE) Exam | Download free PDF with solutions
Test: Process- 2 - Question 1

Consider the following code fragment:
if (fork() == 0)
{ a = a + 5; printf("%d,%d ", a, &a); }
else { a = a –5; printf("%d, %d ", a, &a); }

Let u, v be the values printed by the parent process, and x, y be the values printed by the child process. Which one of the following is TRUE?

Detailed Solution for Test: Process- 2 - Question 1

fork() returns 0 in child process and process ID of child process in parent process. In Child (x), a = a + 5 In Parent (u), a = a – 5; Therefore x = u + 10. The physical addresses of ‘a’ in parent and child must be different. But our program accesses virtual addresses (assuming we are running on an OS that uses virtual memory). The child process gets an exact copy of parent process and virtual address of ‘a’ doesn’t change in child process. Therefore, we get same addresses in both parent and child. See this run for example.

Test: Process- 2 - Question 2

The atomic fetch-and-set x, y instruction unconditionally sets the memory location x to 1 and fetches the old value of x in y without allowing any intervening access to the memory location x. consider the following implementation of P and V functions on a binary semaphore .

void P (binary_semaphore *s) {
     unsigned y;
     unsigned *x = &(s->value);
     do {
           fetch-and-set x, y;
      } while (y);
}
void V (binary_semaphore *s) {
    S->value = 0;
}

 

Q. Which one of the following is true?

Detailed Solution for Test: Process- 2 - Question 2

Let us talk about the operation P(). It stores the value of s in x, then it fetches the old value of x, stores it in y and sets x as 1. The while loop of a process will continue forever if some other process doesn't execute V() and sets the value of s as 0. If context switching is disabled in P, the while loop will run forever as no other process will be able to execute V().

1 Crore+ students have signed up on EduRev. Have you? Download the App
Test: Process- 2 - Question 3

Three concurrent processes X, Y, and Z execute three different code segments that access and update certain shared variables. Process X executes the P operation (i.e., wait) on semaphores a, b and c; process Y executes the P operation on semaphores b, c and d; process Z executes the P operation on semaphores c, d, and a before entering the respective code segments. After completing the execution of its code segment, each process invokes the V operation (i.e., signal) on its three semaphores. All semaphores are binary semaphores initialized to one. Which one of the following represents a deadlockfree order of invoking the P operations by the processes? 

Detailed Solution for Test: Process- 2 - Question 3

Option A can cause deadlock. Imagine a situation process X has acquired a, process Y has acquired b and process Z has acquired c and d. There is circular wait now. Option C can also cause deadlock. Imagine a situation process X has acquired b, process Y has acquired c and process Z has acquired a. There is circular wait now. Option D can also cause deadlock. Imagine a situation process X has acquired a and b, process Y has acquired c. X and Y circularly waiting for each other.
A) for example here all 3 processes are concurrent so X will get semaphore a, Y will get b and Z will get c, now X is blocked for b, Y is blocked for c, Z gets d and blocked for a. Thus it will lead to deadlock. Similarly one can figure out that for B) completion order is Z,X then Y.

Test: Process- 2 - Question 4

A shared variable x, initialized to zero, is operated on by four concurrent processes W, X, Y, Z as follows. Each of the processes W and X reads x from memory, increments by one, stores it to memory, and then terminates. Each of the processes Y and Z reads x from memory, decrements by two, stores it to memory, and then terminates. Each process before reading x invokes the P operation (i.e., wait) on a counting semaphore S and invokes the V operation (i.e., signal) on the semaphore S after storing x to memory. Semaphore S is initialized to two. What is the maximum possible value of x after all processes complete execution?

Detailed Solution for Test: Process- 2 - Question 4

Processes can run in many ways, below is one of the cases in which x attains max value
Semaphore S is initialized to 2 Process W executes S=1, x=1 but it doesn't update the x variable.
Then process Y executes S=0, it decrements x, now x= -2 and signal semaphore S=1
Now process Z executes s=0, x=-4, signal semaphore S=1
Now process W updates x=1, S=2 Then process X executes X=2

So correct option is D

Test: Process- 2 - Question 5

A certain computation generates two arrays a and b such that a[i]=f(i) for 0 ≤ i < n and b[i]=g(a[i]) for 0 ≤ i < n. Suppose this computation is decomposed into two concurrent processes X and Y such that X computes the array a and Y computes the array b. The processes employ two binary semaphores R and S, both initialized to zero. The array a is shared by the two processes. The structures of the processes are shown below.

Process X:                        Process Y:

private i;                              private i;
for (i=0; i < n; i++) {             for (i=0; i < n; i++) {
     a[i] = f(i);                             EntryY(R, S);
     ExitX(R, S);                        b[i]=g(a[i]);
}                                            }

 

Q. Which one of the following represents the CORRECT implementations of ExitX and EntryY?

Detailed Solution for Test: Process- 2 - Question 5

The purpose here is neither the deadlock should occur nor the binary semaphores be assigned value greater than one.
A leads to deadlock
B can increase value of semaphores b/w 1 to n
D may increase the value of semaphore R and S to 2 in some cases

Test: Process- 2 - Question 6

Three concurrent processes X, Y, and Z execute three different code segments that access and update certain shared variables. Process X executes the P operation (i.e., wait) on semaphores a, b and c; process Y executes the P operation on semaphores b, c and d; process Z executes the P operation on semaphores c, d, and a before entering the respective code segments. After completing the execution of its code segment, each process invokes the V operation (i.e., signal) on its three semaphores. All semaphores are binary semaphores initialized to one. Which one of the following represents a deadlock-free order of invoking the P operations by the processes?

Detailed Solution for Test: Process- 2 - Question 6

Option A can cause deadlock. Imagine a situation process X has acquired a, process Y has acquired b and process Z has acquired c and d. There is circular wait now. Option C can also cause deadlock. Imagine a situation process X has acquired b, process Y has acquired c and process Z has acquired a. There is circular wait now. Option D can also cause deadlock. Imagine a situation process X has acquired a and b, process Y has acquired c. X and Y circularly waiting for each other.
Consider option A) for example here all 3 processes are concurrent so X will get semaphore a, Y will get b and Z will get c, now X is blocked for b, Y is blocked for c, Z gets d and blocked for a. Thus it will lead to deadlock. Similarly one can figure out that for B) completion order is Z,X then Y. 

Test: Process- 2 - Question 7

A shared variable x, initialized to zero, is operated on by four concurrent processes W, X, Y, Z as follows. Each of the processes W and X reads x from memory, increments by one, stores it to memory, and then terminates. Each of the processes Y and Z reads x from memory, decrements by two, stores it to memory, and then terminates. Each process before reading x invokes the P operation (i.e., wait) on a counting semaphore S and invokes the V operation (i.e., signal) on the semaphore S after storing x to memory. Semaphore S is initialized to two. What is the maximum possible value of x after all processes complete execution?

Detailed Solution for Test: Process- 2 - Question 7

Background Explanation: A critical section in which the process may be changing common variables, updating table, writing a file and perform another function. The important problem is that if one process is executing in its critical section, no other process is to be allowed to execute in its critical section. Each process much request permission to enter its critical section. A semaphore is a tool for synchronization and it is used to remove the critical section problem which is that no two processes can run simultaneously together so to remove this two signal operations are used named as wait and signal which is used to remove the mutual exclusion of the critical section. as an unsigned one of the most important synchronization primitives, because you can build many other Decrementing the semaphore is called acquiring or locking it, incrementing is called releasing or unlocking.
Solution : Since initial value of semaphore is 2, two processes can enter critical section at a time- this is bad and we can see why. Say, X and Y be the processes.X increments x by 1 and Z decrements x by 2. Now, Z stores back and after this X stores back. So, final value of x is 1 and not -1 and two Signal operations make the semaphore value 2 again. So, now W and Z can also execute like this and the value of x can be 2 which is the maximum possible in any order of execution of the processes. (If the semaphore is initialized to 1, processed would execute correctly and we get the final value of x as -2.) Option (D) is the correct answer.
 Another Solution: Processes can run in many ways, below is one of the cases in which x attains max value Semaphore S is initialized to 2 Process W executes S=1, x=1 but it doesn't update the x variable. Then process Y executes S=0, it decrements x, now x= -2 and signal semaphore S=1 Now process Z executes s=0, x=-4, signal semaphore S=1 Now process W updates x=1, S=2 Then process X executes X=2 So correct option is D 
Another Solution: S is a counting semaphore initialized to 2 i.e., Two process can go inside a critical section protected by S. W, X read the variable, increment by 1 and write it back. Y, Z can read the variable, decrement by 2 and write it back. Whenever Y or Z runs the count gets decreased by 2. So, to have the maximum sum, we should copy the variable into one of the processes which increases the count, and at the same time the decrementing processed should run parallel, so that whatever they write back into memory can be overridden by incrementing process. So, in effect decrement would never happen. 

Test: Process- 2 - Question 8

Fetch_And_Add(X,i) is an atomic Read-Modify-Write instruction that reads the value of memory location X, increments it by the value i, and returns the old value of X. It is used in the pseudocode shown below to implement a busy-wait lock. L is an unsigned integer shared variable initialized to 0. The value of 0 corresponds to lock being available, while any non-zero value corresponds to the lock being not available.

AcquireLock(L){
              while (Fetch_And_Add(L,1))
                         L = 1;
}
ReleaseLock(L){
                         L = 0;
}

 

This implementation

Detailed Solution for Test: Process- 2 - Question 8

Take closer look the below while loop.

while (Fetch_And_Add(L,1))
               L = 1; // A waiting process can be here just after
                       // the lock is released, and can make L = 1.

Consider a situation where a process has just released the lock and made L = 0. Let there be one more process waiting for the lock, means executing the AcquireLock() function. Just after the L was made 0, let the waiting processes executed the line L = 1. Now, the lock is available and L = 1. Since L is 1, the waiting process (and any other future coming processes) can not come out of the while loop. The above problem can be resolved by changing the AcuireLock() to following.

AcquireLock(L){
             while (Fetch_And_Add(L,1))
              { // Do Nothing }
}

Test: Process- 2 - Question 9

A thread is usually defined as a "light weight process" because an operating system (OS) maintains smaller data structures for a thread than for a process. In relation to this, which of the following is TRUE?

Detailed Solution for Test: Process- 2 - Question 9

Threads share address space of Process. Virtually memory is concerned with processes not with Threads. A thread is a basic unit of CPU utilization, consisting of a program counter, a stack, and a set of registers, (and a thread ID.) As you can see, for a single thread of control - there is one program counter, and one sequence of instructions that can be carried out at any given time and for multi-threaded applications-there are multiple threads within a single process, each having their own program counter, stack and set of registers, but sharing common code, data, and certain structures such as open files.

Option (A): as you can see in the above diagram, NOT ONLY CPU Register but stack and code files, data files are also maintained. So, option (A) is not correct as it says OS maintains only CPU register state.
Option (B): according to option (B), OS does not maintain a separate stack for each thread. But as you can see in above diagram, for each thread, separate stack is maintained. So this option is also incorrect.
Option (C): according to option (C), the OS does not maintain virtual memory state. And It is correct as Os does not maintain any virtual memory state for individual thread.
Option (D): according to option (D), the OS maintains only scheduling and accounting information. But it is not correct as it contains other information like cpu registers stack, program counters, data files, code files are also maintained.

Test: Process- 2 - Question 10

Consider the methods used by processes P1 and P2 for accessing their critical sections whenever needed, as given below. The initial values of shared boolean variables S1 and S2 are randomly assigned.

Method Used by P1
while (S1 == S2) ;
Critica1 Section
S1 = S2;

Method Used by P2
while (S1 != S2) ;
Critica1 Section
S2 = not (S1);

 

Q. Which one of the following statements describes the properties achieved?

Detailed Solution for Test: Process- 2 - Question 10

Mutual Exclusion: A way of making sure that if one process is using a shared modifiable data, the other processes will be excluded from doing the same thing. while one process executes the shared variable, all other processes desiring to do so at the same time moment should be kept waiting; when that process has finished executing the shared variable, one of the processes waiting; while that process has finished executing the shared variable, one of the processes waiting to do so should be allowed to proceed. In this fashion, each process executing the shared data (variables) excludes all others from doing so simultaneously. This is called Mutual Exclusion.
Progress Requirement: If no process is executing in its critical section and there exist some processes that wish to enter their critical section, then the selection of the processes that will enter the critical section next cannot be postponed indefinitely.
Solution: It can be easily observed that the Mutual Exclusion requirement is satisfied by the above solution, P1 can enter critical section only if S1 is not equal to S2, and P2 can enter critical section only if S1 is equal to S2. But here Progress Requirement is not satisfied. Suppose when s1=1 and s2=0 and process p1 is not interested to enter into critical section but p2 want to enter critical section. P2 is not able to enter critical section in this as only when p1 finishes execution, then only p2 can enter (then only s1 = s2 condition be satisfied). Progress will not be satisfied when any process which is not interested to enter into the critical section will not allow other interested process to enter into the critical section. 

Test: Process- 2 - Question 11

The enter_CS() and leave_CS() functions to implement critical section of a process are realized using test-and-set instruction as follows:

void enter_CS(X)
{
         while test-and-set(X) ;
}
void leave_CS(X)
{
     X = 0;
}

 

Q. In the above solution, X is a memory location associated with the CS and is initialized to 0. Now consider the following statements: I. The above solution to CS problem is deadlock-free II. The solution is starvation free. III. The processes enter CS in FIFO order. IV More than one process can enter CS at the same time. Which of the above statements is TRUE?

Detailed Solution for Test: Process- 2 - Question 11

The above solution is a simple test-and-set solution that makes sure that deadlock doesn’t occur, but it doesn’t use any queue to avoid starvation or to have FIFO order.

*Multiple options can be correct
Test: Process- 2 - Question 12

Consider a computer C1 has n CPUs and k processes. Which of the following statements are False?

Detailed Solution for Test: Process- 2 - Question 12

The maximum number of processes in ready state is K:

This statement is true. This statement is true. In a system with k processes, all k processes can be in the ready state simultaneously. If Not given Number of process then the number of processes in the ready state at any given time depends on the current scheduling algorithm and the amount of CPU time available. It is not limited by the number of processes or CPUs in the system.

The maximum number of processes in block state is K:

This statement is false. The block state typically represents processes that are waiting for some event or resource, and the number of processes in the block state is not necessarily limited to k. It depends on the nature of the processes and the resources they are waiting for.

The maximum number of processes in running state is K:

This statement is false. The maximum number of processes that can be in the running state simultaneously is limited by the number of CPUs available in the system, which is n in this case, not K.

The maximum number of processes in running state is n:

This statement is true. The number of processes that can be in the running state simultaneously is limited by the number of CPUs available in the system, which is n in this case. If there are more than n processes in the ready state, some of them have to wait until a CPU becomes available.
Hence the correct answer is option 2, and option 3.

Test: Process- 2 - Question 13

The P and V operations on counting semaphores, where s is a counting semaphore, are defined as follows:

P(s) : s = s - 1;
   if (s < 0) then wait;
V(s) : s = s + 1;
    if (s <= 0) then wakeup a process waiting on s;

Assume that Pb and Vb the wait and signal operations on binary semaphores are provided. Two binary semaphores Xb and Yb are used to implement the semaphore operations P(s) and V(s) as follows:

P(s) : Pb(Xb);
    s = s - 1;
   if (s < 0) {
  Vb(Xb) ;
  Pb(Yb) ;
}
else Vb(Xb);

V(s) : Pb(Xb) ;
    s = s + 1;
    if (s <= 0) Vb(Yb) ;
Vb(Xb) ;


The initial values of Xb and Yb are respectively

Detailed Solution for Test: Process- 2 - Question 13

Suppose Xb = 0, then because of P(s): Pb(Xb) operation, Xb will be -1 and processs will get blocked as it will enter into waiting section. So, Xb will be one. Suppose s=2(means 2 process are accessing shared resource), taking Xb as 1,
first P(s): Pb(Xb) operation will make Xb as zero. s will be 1 and Then Vb(Xb) operation will be executed which will increase the count of Xb as one. Then same process will be repeated making Xb as one and s as zero.
Now suppose one more process comes, then Xb will be 1 but s will be -1 which will make this process go into loop (s <0) and will result into calling Vb(Xb) and Pb(Yb) operations. Vb(Xb) will result into Xb as 2 and Pb(Yb) will result into decrementing the value of Yb.

case 1: if Yb has value as 0, it will be -1 and it will go into waiting and will be blocked.total 2 process will access shared resource (according to counting semaphore, max 3 process can access shared resource) and value of s is -1 means only 1 process will be waiting for resources and just now, one process got blocked. So it is still true.
case 2: if Yb has value as 1, it will be 0. Total 3 process will access shared resource (according to counting semaphore, max 3 process can access shared resource) and value of s is -1 means only 1 process will be waiting for resources and but there is no process waiting for resources.So it is false.

Test: Process- 2 - Question 14

Information about a process is maintained in a ______.

Detailed Solution for Test: Process- 2 - Question 14

Process control block: It is a data structure that is maintained by the Operating System for every process. A process state is a condition of the process at a specific instant of time. Every process is represented in the operating system by a process control block, which is also called a task control block.

Hence the correct answer is process control block.

Test: Process- 2 - Question 15

A process executes the following code

for (i = 0; i < n; i++) fork();

The total number of child processes created is

Detailed Solution for Test: Process- 2 - Question 15

If we sum all levels of above tree for i = 0 to n-1, we get 2^n - 1. So there will be 2^n – 1 child processes. Also see this post for more details.

Test: Process- 2 - Question 16

Which of the following types of operating systems is non- interactive?

Detailed Solution for Test: Process- 2 - Question 16

Batch Operating System does not interact with the computer directly. There is an operator which takes similar jobs having the same requirement and group them into batches. It is the responsibility of the operator to sort jobs with similar needs.

Hence the correct answer is the Batch processing operating system.

Test: Process- 2 - Question 17

Consider the following statements about user level threads and kernel level threads. Which one of the following statement is FALSE?

Detailed Solution for Test: Process- 2 - Question 17

Kernel level threads are managed by the OS, therefore, thread operations are implemented in the kernel code. Kernel level threads can also utilize multiprocessor systems by splitting threads on different processors. If one thread blocks it does not cause the entire process to block. Kernel level threads have disadvantages as well. They are slower than user level threads due to the management overhead. Kernel level context switch involves more steps than just saving some registers. Finally, they are not portable because the implementation is operating system dependent.
Option (A): Context switch time is longer for kernel level threads than for user level threads. True, As User level threads are managed by user and Kernel level threads are managed by OS. There are many overheads involved in Kernel level thread management, which are not present in User level thread management. So context switch time is longer for kernel level threads than for user level threads.
Option (B): User level threads do not need any hardware support True, as User level threads are managed by user and implemented by Libraries, User level threads do not need any hardware support.
Option (C): Related kernel level threads can be scheduled on different processors in a multi- processor system. This is true.
Option (D): Blocking one kernel level thread blocks all related threads. false, since kernel level threads are managed by operating system, if one thread blocks, it does not cause all threads or entire process to block. 

Test: Process- 2 - Question 18

The program in the operating system that does processor management is called _______.

Detailed Solution for Test: Process- 2 - Question 18

In a multiprogramming environment, the operating system determines which processes receive processor time and for how long. Process scheduling is the name for this function. For processor management, an operating system performs the following tasks:

  • The primary goal of the Traffic controller is to coordinate and control the actions of hardware and software in the C.P.U.
  • Keep track of the processor and the process's state. The traffic controller is the program that is in charge of this task.
  • Allocates the processor (CPU) to a process.
  • De-allocates processor when a process is no longer required.

Major Points

  • After the scheduler, the dispatcher is finished. It assigns CPU control to the process chosen by the short-term scheduler. The dispatcher assigns CPU to the process when it has been chosen.
  • Process scheduling is the action of process management, which involves removing a running process from the CPU and selecting a new process based on a set of rules.
  • The new process is brought to the 'Ready State' by a long-term or job scheduler. It regulates the Degree of Multi-programming or the number of processes that are ready at any given time.
Test: Process- 2 - Question 19

Two processes, P1 and P2, need to access a critical section of code. Consider the following synchronization construct used by the processes:Here, wants1 and wants2 are shared variables, which are initialized to false. Which one of the following statements is TRUE about the above construct?v

   /* P1 */
while (true) {
     wants1 = true;
     while (wants2 == true);
     /* Critical
         Section */
    wants1=false;
}
/* Remainder section */

/* P2 */
while (true) {
    wants2 = true;
    while (wants1==true);
     /* Critical
        Section */
     wants2 = false;
}
/* Remainder section */

Detailed Solution for Test: Process- 2 - Question 19

Bounded waiting :There exists a bound, or limit, on the number of times other processes are allowed to enter their critical sections after a process has made request to enter its critical section and before that request is granted. mutual exclusion prevents simultaneous access to a shared resource. This concept is used in concurrent programming with a critical section, a piece of code in which processes or threads access a shared resource. Solution: Two processes, P1 and P2, need to access a critical section of code. Here, wants1 and wants2 are shared variables, which are initialized to false. Now, when both wants1 and wants2 become true, both process p1 and p2 enter in while loop and waiting for each other to finish. This while loop run indefinitely which leads to deadlock. Now, Assume P1 is in critical section (it means wants1=true, wants2 can be anything, true or false). So this ensures that p2 won’t enter in critical section and vice versa. This satisfies the property of mutual exclusion. Here bounded waiting condition is also satisfied as there is a bound on the number of process which gets access to critical section after a process request access to it. 

Test: Process- 2 - Question 20

What name is given to a program in execution?

Detailed Solution for Test: Process- 2 - Question 20

A process is the instance of a computer program that is being executed. It contains the program code and its activity. A process may be made up of multiple threads of execution that execute instructions concurrently.

Program in execution is called process. The process is an active entity.

Hence the correct answer is process.

Information about Test: Process- 2 Page
In this test you can find the Exam questions for Test: Process- 2 solved & explained in the simplest way possible. Besides giving Questions and answers for Test: Process- 2, EduRev gives you an ample number of Online tests for practice

Top Courses for Computer Science Engineering (CSE)

Download as PDF

Top Courses for Computer Science Engineering (CSE)