You are on page 1of 6

Advanced Operating System

Department : IITA Student ID : BIA110004 Name : 哈瓦尼

Chapter 3
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:
Context switch time pure overhead, because system does no useful work while switching.
Context switch times are highly dependent on hardware support. In Sun Ultra SPARC,
context switch simply requires the CPU current-register-set pointer is changed to the
register set containing the new context, which takes very little time.
If the new context is in memory rather than register set and all the register sets are in use,
then 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 new context is already on one of the register set.

3.5 When a process creates a new process using the fork() operation, which of the following
states is shared between the parent process and the child process?
a. Stack
b. Heap
c. Shared memory segments
Answer:
Part 1:
When a process uses the fork() to create a new process, all the new processes
corresponding to the parent process are created and loaded into a separate memory
location for the child process by the operating system. The parent process and the newly
created child process only share the shared memory segments.
Therefore, the correct answer is C) Shared memory segments.
Part 2:
Stacks and heads are not shared by these procceses. Instead, new copies of the stack and
the head are made for the newly created process, when a process tries to write into these.
There, the option "a. Stack" and "b. Heap" are incorrect.
3.6 Consider the “exactly once” semantic with respect to the RPC mechanism. Does the
algorithm for implementing this semantic execute correctly even if the ACK message sent
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)
scheme combined 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.

3.7 Assume that a distributed system is susceptible to server failure. What mechanisms
would be required to guarantee the “exactly once” semantic 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.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.
#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;
}
Figure 3.33 When will LINE J be reached?

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, but the process
monitor tool, available from technet.microsoft.com, provides a process-tree tool.
Answer:
Child CompleteLINE J
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("Line J"); would be performed

3.11 Explain the role of the init process on UNIX and Linux systems in regard 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 init process 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.

Chapter 4
4.4 What resources are used when a thread is created? How do they differ from those used
when a process is created?
Answer:

 A thread is a basic unit of CPU utilization, also known as light weight process. So,
creating either a user or kernel thread involves allocating a small data structure to
hold a thread ID, a program counter, a register set, stack and priority, whereas
creating a process involves allocating the large data structure called as PCB(Process
Control Block) which includes a memory map, list of open files, and environment
variables. Allocating and managing the memory map is typically the most time-
consuming activity.

Resources are used when a thread is created:

(1) Code section


(2) Data section
(3) Other operation system resources such as open files and signals with other threads
belonging to the same process whereas each and every process has separate code
section, data section and operating system resources.

4.6 Provide two programming examples in which multithreading does not provide better
performance than a single-threaded solution.
Answer:
(1) Any sequential program is to be single threaded. For example, a program that
calculates the gross salary, net salary, and tax of an employee gives better
performance when it is single threaded.
(2) Shell program such as the C-shell or Korn shell is to be single threaded as such
programs require close monitoring of its workspace. While executing the program,
the files that are environment variables etc. are to be closely observed.

4.7 Under what circumstances does a multithreaded solution using multiple kernel threads
provide better performance than a single-threaded solution on a single-processor system?
Answer:
When a kernel thread suffers a page fault, another kernelthread can be switched in to use
the interleaving time in a useful lmanner. A single-threaded process, on the other hand, will
not be capable of performing useful work when a page fault takes place. Therefore,
inscenarios where a program might suffer from frequent page faults orhas to wait for other
system events, a multithreaded solution wouldperform better even on a single-processor
system.

4.10 In Chapter 3, we discussed Google’s Chrome browser and its practice of opening each
new website in a separate process. Would the same benefits have been achieved if instead
Chrome had been designed to open each new website in a separate thread? Explain.
Answer:
Processes and threads both can typically be defined as sequences of execution, for any
program. The main difference lies beneath the memory space they share on the RAM or
main memory of the system while getting executed.

 Each process acquires a unique address space on the memory; whereas threads of a
program usually share the same memory space for their execution.
 Processes act independently while threads always remain dependent on their
consequent thread for their execution. Threads remain a chain of instructions where
a small breakdown may terminate the entire execution.
 Google Chrome browser maintains to open each new website as an independent
process rather than opening them as threads to ensure that no website breakdown
affects others' service.
 One cannot maintain the efficiency of the browser while opening each new website
as a thread, because threads are allocated with shared memory spaces. Hence they
may affect each other if one of them crashes unexpectedly.

4.13 Determine if the following problems exhibit task or data parallelism:


• The multithreaded statistical program described in Exercise 4.21
• The multithreaded Sudoku validator described in Project 1 in this chapter
• The multithreaded sorting program described in Project 2 in this chapter
• The multithreaded web server described in Section 4.1
Answer:

 The statistical program is Data Parallelism. Here, multiple threads are created and
each thread is performing functions like calculating average, finding minimum value,
finding maximum value on same data.
 So in order to perform these operations it creates threads and does the operation in
parallel for task completion.
 The multithreaded Sudoku validator is Task Parallelism. Here, in Sudoku solution
example, there are constraints that each row or column should contain the digits
from 1 to 9. And each grid should have digits from 1 to 9, which can go when one
thread completes, it starts another until all eleven threads.
So here it takes task from one thread to another, until it completes and satisfies all tasks and
these tasks need not to run concurrently.

 The multithreaded sorting program is Data Parallelism. Here, in sorting list, the list is
divided in two half threads runs concurrently and execute individually to provide
resultant threads and then.
 The multithreaded web server is Task Parallelism. In single threaded, the threads
which are created are able to perform only one task, whereas, multithreaded creates
threads in such a way that is able to perform multitask at a time leading to better
performance.

You might also like