GATE 2005
203 questions
MCQ 2031-mark 203
Questions 146–150 of 203
The grammar is not suitable for predictive-parsing because the grammar is:
Answer: (A)
The grammar is ambiguous. The empty string has many parse trees: , and also , and so on. The string also has several trees, for example and (with the second A empty).
A predictive (LL(1)) parser picks the production from one lookahead symbol using a table. For an ambiguous grammar some table cell must hold more than one production. Here , and would each hold both and (and for '('). So the parser cannot choose.
The grammar is also left-recursive because of , but left recursion can be removed by a standard rewriting. Ambiguity cannot be removed in the same way, and a grammar that is still ambiguous after the rewrite cannot be LL(1). So ambiguity is the basic reason. Right-recursion is not a problem for predictive parsing, and has two adjacent non-terminals, so it is not an operator grammar either.
Answer: (A)
A predictive (LL(1)) parser picks the production from one lookahead symbol using a table. For an ambiguous grammar some table cell must hold more than one production. Here , and would each hold both and (and for '('). So the parser cannot choose.
The grammar is also left-recursive because of , but left recursion can be removed by a standard rewriting. Ambiguity cannot be removed in the same way, and a grammar that is still ambiguous after the rewrite cannot be LL(1). So ambiguity is the basic reason. Right-recursion is not a problem for predictive parsing, and has two adjacent non-terminals, so it is not an operator grammar either.
Answer: (A)
A user level process in Unix traps the signal sent on a Ctrl-C input, and has a signal handling routine that saves appropriate files before terminating the process. When a Ctrl-C input is given to this process, what is the mode in which the signal handling routine executes?
Answer: (A)
Pressing Ctrl-C is handled first by the kernel (the terminal driver), which sends the signal SIGINT to the process. This part runs in kernel mode.
The process has installed its own handler. The handler is ordinary code written by the user and it lives in the process's own address space. The kernel does not run user code with full privileges, so it switches back to user mode and runs the handler there. When the handler returns, the process goes back into the kernel briefly (the sigreturn call) and then continues.
Why the others are wrong: kernel mode and privileged mode are two names for the same CPU mode, and the handler does not run in it. "Superuser" is a kind of user (root) and not a CPU mode.
Answer: (A)
The process has installed its own handler. The handler is ordinary code written by the user and it lives in the process's own address space. The kernel does not run user code with full privileges, so it switches back to user mode and runs the handler there. When the handler returns, the process goes back into the kernel briefly (the sigreturn call) and then continues.
Why the others are wrong: kernel mode and privileged mode are two names for the same CPU mode, and the handler does not run in it. "Superuser" is a kind of user (root) and not a CPU mode.
Answer: (A)
The shell command
is executed in /etc directory of a computer system running Unix. Which of the following shell commands will give the same information as the above command when executed in the same directory?
find -name passwd -print is executed in /etc directory of a computer system running Unix. Which of the following shell commands will give the same information as the above command when executed in the same directory?
Answer: (A)
find -name passwd -print prints the path of every file named passwd in the current directory and below. In /etc it tells you that a file named passwd exists there.ls passwd prints the name passwd if that file exists in the current directory, so it gives the same information. It does not search subdirectories, but it is the closest match.The other options work on the contents of the file:
cat passwd prints the contents, grep name passwd prints the lines containing the text "name", and grep print passwd prints the lines containing the text "print". None of them looks up a file by its name.Answer: (A)
Consider the following code fragment:
if (fork() == 0)
{ a = a + 5; printf("%d,%d\n", a, &a); }
else { a = a - 5; printf("%d, %d\n", 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?Answer: (C)
Let be the value of a before fork.
fork() returns 0 in the child and a non-zero value in the parent. So the child runs the first branch and the parent runs the else branch.
Parent: . Child: . So , that is .
The child gets a copy of the parent's address space, so is at the same virtual (logical) address in both. The address printed by &a is a virtual address, so . The two copies of a sit in different physical memory, so changing a in one process does not change it in the other. That is why the values differ while the addresses are equal.
Options A and B are wrong because they give (the parent's value is the smaller one). Option D is wrong because it says the addresses differ.
Answer: (C)
fork() returns 0 in the child and a non-zero value in the parent. So the child runs the first branch and the parent runs the else branch.
Parent: . Child: . So , that is .
The child gets a copy of the parent's address space, so is at the same virtual (logical) address in both. The address printed by &a is a virtual address, so . The two copies of a sit in different physical memory, so changing a in one process does not change it in the other. That is why the values differ while the addresses are equal.
Options A and B are wrong because they give (the parent's value is the smaller one). Option D is wrong because it says the addresses differ.
Answer: (C)
What is the swap space in the disk used for?
Answer: (B)
Swap space on the disk holds the pages of processes that are swapped out of main memory when memory is short. Those pages are the process data (and code), so swap space is used for saving process data.
- (A) Temporary html pages are ordinary files, not swap.
- (C) The super-block is file system data kept in the file system itself.
- (D) Device drivers are kept as normal files or in the kernel.
Answer: (B)
- (A) Temporary html pages are ordinary files, not swap.
- (C) The super-block is file system data kept in the file system itself.
- (D) Device drivers are kept as normal files or in the kernel.
Answer: (B)