Nothing Special   »   [go: up one dir, main page]

Untitled

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Chapter3 processes

Solution

3.1 Using the program shown in Figure 3.30, explain what the output will be at Line A.
Answer:
The result is still 5 as the child updates its copy of value. When control returns to the parent, its value
remains at 5.

3.2 Including the initial parent process, how many processes are created by
the program shown in Figure 3.31?
Answer:
There are 8 processes created.

3.3 Original versions of Apple’s mobile iOS operating system provided no


means of concurrent processing. Discuss three major complications that concurrent processing adds to an
operating system.
Answer: FILL

3.4 The Sun UltraSPARC processor has multiple register sets. Describe what happens when a context switch
occurs if the new context is already loaded into one of the register sets. What happens if the new context is
in memory rather than in a register set and all the register sets are in use?
Answer:
The CPU current-register-set pointer is changed to point to the set containing the new context, which takes
very little time. If the context is in memory, one of the contexts in a register set must be chosen and be
moved to memory, and the new context must be loaded from memory into the set. This process takes a little
more time than on systems with one set of registers, depending on how a replacement victim is selected.

3.5 When a process creates a new process using the fork() operation, which
of the following state is shared between the parent process and the child process?
a. Stack
b. Heap
c. Shared memory segments
Answer:
Only the shared memory segments are shared between the parent process and the newly forked child
process. Copies of the stack and the heap are made for the newly created process.

3.7 Assume that a distributed system is susceptible to server failure. What mechanisms would be required to
guarantee the “exactly once” semantics for execution of RPCs?
Answer:
The server should keep track in stable storage (such as a disk log) information regarding what RPC operations
were received, whether they were successfully performed, and the results associated with the operations.
When a server crash takes place and a RPC message is received, the server can check whether the RPC had
been previously performed and therefore guarantee “exactly once”semanctics for the execution of RPCs.
3.8 Describe the differences among short-term, medium-term, and long-term scheduling.
Answer:
a. Short-term (CPU scheduler)—selects from jobs in memory those jobs that are ready to execute and
allocates the CPU to them.
b. Medium-term—used especially with time-sharing systems as an intermediate scheduling level. A
swapping scheme is implemented to remove partially run programs from memory and reinstate them later
to continue where they left off.
c. Long-term (job scheduler)—determines which jobs are brought into memory for processing. The primary
difference is in the frequency of their execution. The short- term must select a new process quite often.
Long-term is used much less often since it handles placing jobs in the system and may wait a while for a job
to finish before it admits another one.

3.9 Describe the actions taken by a kernel to context-switch between processes


Answer:
In general, the operating system must save the state of the currently running process and restore the state
of the process scheduled to be run next. Saving the state of a process typically includes the values of all the
CPU registers in addition to memory allocation. Context switches must also perform many architecture-
specific operations, including flushing data and instruction caches.

3.10 Construct a process tree similar to Figure 3.8. To obtain process information for the UNIX or Linux
system, use the command ps -ael. Use the command man ps to get more information about the ps
command. The task manager on Windows systems does not provide the parent process id,yet the process
monitor tool available from technet.microsoft.com provides a process tree tool.
Answer:
Results will vary widely.

3.11 Explain the role of the init process on UNIX and Linux systems in regards to process termination.
Answer:
When a process is terminated, it briefly moves to the zombie state and remains in that state until the parent
invokes a call to wait(). When this occurs, the process id as well as entry in the process table are both
released. However,if a parent does not invoke wait(), the child process remains a zombie as long as the
parent remains alive. Once the parent process terminates, the initprocess becomes the new parent of the
zombie. Periodically, the init process calls wait() which ultimately releases the pid and entry in the process
table of the zombie process.

3.15 Give an example of a situation in which ordinary pipes are more suitable than named pipes and an
example of a situation in which named pipes are more suitable than ordinary pipes.
Answer:
Simple communication works well with ordinary pipes. For example, assume we have a process that counts
characters in a file. An ordinary pipe can be used where the producer writes the file to the pipe and the
consumer reads the files and counts the number of characters in the file. Next, for an example where named
pipes are more suitable, consider the situation where several processes may write messages to a log. When
processes wish to write a message to the log, they write it to the named pipe. A server reads the messages
from the named pipe and writes them to the log file.
3.12 Including the initial parent process, how many processes are created by the program shown in Figure
3.32?
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
int main()
{
pid t pid;
/* fork a child process */
pid = fork();
if (pid < 0) { /* error occurred */
fprintf(stderr, "Fork Failed");
return 1;
}
else if (pid == 0) { /* child process */
execlp("/bin/ls","ls",NULL);
printf("LINE J");
}
else { /* parent process */
/* parent will wait for the child to complete */
wait(NULL);
printf("Child Complete");
}
return 0;
}
Answer:
8 processes are created. The program online includes printf() statements to better understand how many
processes have been created.

3.13 Explain the circumstances when the line of code marked printf("LINEJ") in Figure 3.33 is reached.
Answer:
The call to exec() replaces the address space of the process with the program specified as the parameter to
exec(). If the call to exec() succeeds, the new program is now running and control from the call to exec()
never returns. In this scenario, the line printf("Line J"); would never be performed. However, if an error
occurs in the call to exec(), the function returns control and therefor the line printf("LineJ"); would be
performed.

3.14 Using the program in Figure Figure 3.34, identify the values of pid at lines A,B,C, and D. (Assume that
the actual pids of the parent and child are 2600 and 2603, respectively.)
Answer:
A = 0, B = 2603, C = 2603, D = 2600
3.16 Consider the RPC mechanism. Describe the undesirable consequences that could arise from not
enforcing either the “at most once" or “exactly once" semantic. Describe possible uses for a mechanism that
has neither of these guarantees.
Answer:
If an RPC mechanism cannot support either the “at most once”or “at least once”semantics, then the RPC
server cannot guarantee that a remote procedure will not be invoked multiple occurrences. Consider if a
remote procedure were withdrawing money from a bank account on a system that did not support these
semantics. It is possible that a single invocation of the remote procedure might lead to multiple withdrawals
on the server. For a system to support either of these semantics generally requires the server maintain some
form of client state such as the timestamp described in the text. If a system were unable to support either of
these semantics, then such a system could only safely provide remote procedures that do not alte data or
provide time-sensitive results. Using our bank account as an example, we certainly require “at most once”or
“at least once”semantics for performing a withdrawal (or deposit!). However, an inquiry into an account
balance or other account information such as name, address, etc. does not require these semantics.

3.17 Using the program shown in Figure 3.35, explain what the output will be at lines Xand Y.
Answer:
Because the child is a copy of the parent, any changes the child makes will occur in its copy of the data and
won’t be reflected in the parent. As a result, the values output by the child at line X are 0, -1, -4, -9, -16. The
values output by the parent at line Y are 0, 1, 2, 3, 4
3.18 What are the benefits and the disadvantages of each of the following? Consider both the system level
and the programmer level.
a. Synchronous and asynchronous communication b.Automatic and explicit buffering
b. Send by copy and send by reference
c. Fixed-sized and variable-sized messages
Answer:
a. Synchronous and asynchronous communication—A benefit of synchronous communication is that it
allows a rendezvous between the sender and receiver. A disadvantage of a blocking send is that a
rendezvous may not be required, and the message could be delivered asynchronously. As a result, message-
passing systems often provide both forms of synchronization.
b. Automatic and explicit buffering—Automatic buffering providesa queue with indefinite length, thus
ensuring the sender will never have to block while waiting to copy a message. There are no specifications on
how automatic buffering will be provided; one scheme may reserve sufficiently large memory where much
of the memory is wasted. Explicit buffering specifies how large the buffer is. In this situation, the sender may
be blocked while waiting for available space in the queue. However, it is less likely that memory will be
wasted with explicit buffering.
c. Send by copy and send by reference—Send by copy does not allow the receiver to alter the state of the
parameter; send by reference does allow it. A benefit of send by reference is that it allows the programmer
to write a distributed version of a centralized application. Java’s RMI provides both; however, passing a
parameter by reference requires declaring the parameter as a remote object as well.
d. Fixed-sized and variable-sized messages—The implications of this are mostly related to buffering issues;
with fixed-size messages, a buffer with a specific size can hold a known number of messages.The number of
variable-sized messages that can be held by such a buffer is unknown. Consider how Windows 2000 handles
this situation: with fixed-sized messages (anything <256 bytes), the messages are copied from the address
space of the sender to the address space of the receiving process. Larger messages (i.e., Variable-sized
messages) use shared memory to pass the message.
3.6 With respect to the RPC mechanism, consider the “exactly once”semantic. Does the algorithm for
implementing this semantic execute correctly even if the ACK message back to the client is lost due to a
network problem? Describe the sequence of messages and discuss whether “exactly once”is still preserved.
Answer:
The “exactly once”semantics ensure that a remore procedure will be executed exactly once and only once.
The general algorithm for ensuring this combines an acknowledgment (ACK)schemecombined with
timestamps (or some other incremental counter that allows the server to distinguish between duplicate
messages). The general strategy is for the client to send the RPC to the server along with a timestamp. The
client will also start a timeout clock. The client will then wait for one of two occurrences: (1) it will receive an
ACK from the server indicating that the remote procedure was performed,
or (2) it will time out. If the client times out, it assumes the server was unable to perform the remote
procedure so, the client invokes the RPC a second time, sending a later timestamp. The client may not
receive the ACK for one of two reasons: (1) the original RPC was never received by the server, or (2) the RPC
was correctly received—and performed—by the server but the ACK was lost. In situation (1), the use of ACKs
allows the server ultimately to receive and perform the RPC. In situation (2), the server will receive a
duplicate RPC and it will use the timestamp to identify it as a duplicate so as not to perform the RPC a
second time. It is important to note that the server must send a second ACK back to the client to inform the
client the RPC has been performed.

You might also like