GATE 2004
199 questions
MCQ 1991-mark 199
Questions 131–135 of 199
Consider the grammar rule for arithmetic expressions. The code generated is targeted to a CPU having a single user register. The subtraction operation requires the first operand to be in the register. If E1 and E2 do not have nay-common sub-expression, in order to get the shortest possible code
Answer: (B)
Evaluate first.
There is only one register, and the subtraction needs in it.
- first: compute and store it in a temporary memory location. Then compute , which stays in the register, and subtract the temporary directly from memory.
- first: compute and store it, since computing needs the register. After is computed it sits in the register, but the subtraction needs there. So has to be stored too and loaded back. This takes extra store and load instructions.
Evaluating first gives the shortest code. The order matters, and no interleaving is needed.
Answer: (B)
There is only one register, and the subtraction needs in it.
- first: compute and store it in a temporary memory location. Then compute , which stays in the register, and subtract the temporary directly from memory.
- first: compute and store it, since computing needs the register. After is computed it sits in the register, but the subtraction needs there. So has to be stored too and loaded back. This takes extra store and load instructions.
Evaluating first gives the shortest code. The order matters, and no interleaving is needed.
Answer: (B)
Consider a program P that consists of two source modules M1 and M2 contained in two different files. If M1 contains a reference to a function defined in M2 the reference will be resolved at
Answer: (C)
Each module is compiled on its own. While compiling M1, the compiler does not see M2, so it cannot know the address of the M2 function. It leaves the call as an unresolved external symbol in the object file of M1.
The linker then joins the object files, matches that symbol with the definition in M2 and fills in the address. So the reference is resolved at link time. For example, with gcc:
Answer: (C)
The linker then joins the object files, matches that symbol with the definition in M2 and fills in the address. So the reference is resolved at link time. For example, with gcc:
gcc -c c1.c -o c1.o gcc -c c2.c -o c2.o gcc c1.o c2.o -o C.exeThe first two commands only compile. The last command links.
Answer: (C)
A process executes the following segment of code :
for(i = 1; i <= n; i++)
fork ();
The number of new processes created is
Answer: (C)
Each call to fork() creates one new process, and the new process continues the loop too. So every loop iteration doubles the number of processes.
After each iteration the total is 1, 2, 4, 8, ..., after iterations. One of these is the original process, so the number of new processes is . For : the parent forks C1; then the parent forks C2 and C1 forks C3, which is new processes.
Answer: (C)
After each iteration the total is 1, 2, 4, 8, ..., after iterations. One of these is the original process, so the number of new processes is . For : the parent forks C1; then the parent forks C2 and C1 forks C3, which is new processes.
Answer: (C)
Which one of the following is NOT shared by the threads of the same process ?
Answer: (A)
Each thread has its own stack, because a thread runs its own chain of function calls. The stack holds the return addresses, parameters and local variables of those calls, and different threads have different ones.
The other items belong to the process as a whole, so all its threads share them:
- the address space (code, global data and heap)
- the file descriptor table (open files)
- message queues, which are opened by the process, so all its threads can use them
Answer: (A)
The other items belong to the process as a whole, so all its threads share them:
- the address space (code, global data and heap)
- the file descriptor table (open files)
- message queues, which are opened by the process, so all its threads can use them
Answer: (A)
Consider the following statements with respect to user-level threads and kernel-supported threads
(i) context switch is faster with kernel-supported threads
(ii) for user-level threads, a system call can block the entire process
(iii) Kernel supported threads can be scheduled independently
(iv) User level threads are transparent to the kernel
Which of the above statements are true?
(i) context switch is faster with kernel-supported threads
(ii) for user-level threads, a system call can block the entire process
(iii) Kernel supported threads can be scheduled independently
(iv) User level threads are transparent to the kernel
Which of the above statements are true?
Answer: (A)
- (i) is false. A user-level thread switch is done by the thread library inside the process, with no kernel call, so it is faster than a kernel-thread switch.
- (ii) is true. The kernel sees only one process, so when one user-level thread makes a blocking system call, the kernel blocks the whole process and every thread in it stops.
- (iii) is true. The kernel knows each kernel-supported thread, so it can schedule each one on its own (even on different CPUs).
- (iv) is true. The kernel does not know that user-level threads exist; it sees only the single process that holds them.
So (ii), (iii) and (iv) are true.
Answer: (A)
- (ii) is true. The kernel sees only one process, so when one user-level thread makes a blocking system call, the kernel blocks the whole process and every thread in it stops.
- (iii) is true. The kernel knows each kernel-supported thread, so it can schedule each one on its own (even on different CPUs).
- (iv) is true. The kernel does not know that user-level threads exist; it sees only the single process that holds them.
So (ii), (iii) and (iv) are true.
Answer: (A)