GATE 2008
185 questions
MCQ 1851-mark 52 · 2-mark 133
Questions 136–140 of 185
Some code optimizations are carried out on the intermediate code because
Answer: (A)
Intermediate code does not depend on the machine. If the optimizations are done on it, the same optimizer can be reused for many target processors, and only the code generator has to be rewritten for each new target. If the optimization were done on target code, it would have to be redone for every architecture. So doing some optimization on intermediate code improves the portability of the compiler.
(B) is at most a side benefit: intermediate code is simpler to analyse because it has no machine details, but that is not the main reason.
(C) is wrong: dataflow information can also be used on target code, so it is not true that it cannot be used otherwise.
(D) is wrong: information from the front end (such as types and the symbol table) can also be passed on to later phases, so it is not true that it cannot be used otherwise.
Answer: (A)
(B) is at most a side benefit: intermediate code is simpler to analyse because it has no machine details, but that is not the main reason.
(C) is wrong: dataflow information can also be used on target code, so it is not true that it cannot be used otherwise.
(D) is wrong: information from the front end (such as types and the symbol table) can also be passed on to later phases, so it is not true that it cannot be used otherwise.
Answer: (A)
Consider the execution of the following commands in a shell on a Linux operating system.
bash$ cat alpha
Mathematics
bash$ ln alpha beta
bash$ rm alpha
bash$ cat >> beta << SAME
Information Technology
SAME
bash$ cat beta
The output of the last command will be:
bash$ cat alpha
Mathematics
bash$ ln alpha beta
bash$ rm alpha
bash$ cat >> beta << SAME
Information Technology
SAME
bash$ cat beta
The output of the last command will be:
Answer: (B)
ln alpha beta makes beta a second name (a hard link) for the same file as alpha, with the same data on disk.rm alpha removes only the name alpha. The data stays because the name beta still points to it, so beta still holds Mathematics.cat >> beta << SAME appends the lines typed before the line SAME. The word SAME only marks the end of the input and is not written to the file. So Information Technology is added after Mathematics.cat beta prints Mathematics, then Information Technology.Answer: (B)
A process executes the following code
for (i = 0; i < n; i++) fork( );The total number of child processes created isAnswer: (B)
Each call to fork() creates one child, and the child continues from the same point, so it runs the remaining loop iterations too. So every fork doubles the number of processes.
After each loop iteration the count is 1, 2, 4, 8, ..., up to after iterations. Only one of these is the original process, and all the others are children. So the number of children is .
Answer: (B)
After each loop iteration the count is 1, 2, 4, 8, ..., up to after iterations. Only one of these is the original process, and all the others are children. So the number of children is .
Answer: (B)
A client process P needs to make a TCP connection to a server process S. Consider the following situation: the server process S executes a socket(), a bind() and a listen() system call in that order, following which it is preempted. Subsequently, the client process P executes a socket() system call followed by connect() system call to connect to the server process S. The server process has not executed any accept() system call. Which one of the following events could take place?
Answer: (A)
After
The client's
An error (option C) would come only if nothing were listening on the port (the client would get a reset) or if the backlog were full. Blocking (B) lasts only for the short handshake, and a core dump (D) does not occur.
Answer: (A)
listen(), the server's kernel handles the TCP handshake by itself. When the client's SYN arrives, the kernel replies with SYN+ACK and, once the client's ACK comes, puts the finished connection in the listen backlog queue.accept() does not take part in the handshake. It only removes an already established connection from that queue.The client's
connect() returns as soon as it gets the SYN+ACK, so it returns successfully even though the server process was preempted and has not called accept().An error (option C) would come only if nothing were listening on the port (the client would get a reset) or if the backlog were full. Blocking (B) lasts only for the short handshake, and a core dump (D) does not occur.
Answer: (A)
Which of the following system calls results in the sending of SYN packets?
Answer: (D)
- makes a new socket of a given socket type. The socket is identified by an integer, and system resources are given to it. It sends no packet.
- is mostly used on the server side. It ties a socket to a socket address structure, which means a given local port number and IP address. It sends no packet.
- is used on the server side. It puts a bound TCP socket into the listening state. It sends no packet.
- is used on the client side. It gives the socket a free local port number. For a TCP socket, it tries to set up a new TCP connection.
When the client calls , the three-way handshake takes place:
1. The client asks for a connection by sending a SYN (synchronize) message to the server.
2. The server accepts the request by sending SYN-ACK back to the client.
3. The client replies with an ACK, and the connection is set up.
So only sends a SYN packet.
Answer: (D)
- is mostly used on the server side. It ties a socket to a socket address structure, which means a given local port number and IP address. It sends no packet.
- is used on the server side. It puts a bound TCP socket into the listening state. It sends no packet.
- is used on the client side. It gives the socket a free local port number. For a TCP socket, it tries to set up a new TCP connection.
When the client calls , the three-way handshake takes place:
1. The client asks for a connection by sending a SYN (synchronize) message to the server.
2. The server accepts the request by sending SYN-ACK back to the client.
3. The client replies with an ACK, and the connection is set up.
So only sends a SYN packet.
Answer: (D)