Chapter 3 operating systems

Ace your homework & exams now with Quizwiz!

If call fails and no new processes are created then the return value will be??

-1

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

-In context-switching between one process to another, the kernel must save the state of the current task running on the system before switching to another task.

What does fork() do?

The fork() is a system call that creates a new process. A system call splits a process into two processes.

What does the kernel perform the state save on and what does it load from/to do?

The kernel performs the state save on the currently running task and loads the data information of the new task from the PCB to run.

What does the kernel do after the completion of the new task? what is this also known as

The kernel switches to the old task by loading the data information of the old task from the PCB to run. This method is referred to as state restore.

What happens if call fails and no new processes are created?

Then it will return -1.

What happens to the memory pages that are used by the original processes? In turn, what does this say about the memory of the parent and child?

They are duplicated and thus the parent and child will get the same image because they have the same memory as the original process.

Describe medium term scheduling.

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.

What do PCBs do? What is it also known as?

a data structure in the operating system kernel containing the information needed to manage the scheduling of a particular process. The PCB is "the manifestation of a process in an operating system"

What is another name for a distributed version of centralized application

shared memory implications

If the call returns in child process, then the return value will be??

0

What either two occurrences will the client wait for?

1. It will receive an ACK from the server indicating that the remote procedure was performed 2. It will time out

What are two reasons that the client may not receive the ACK?

1. The original RPC was never received by the server 2. The RPC was correctly received -and performed- by the server but the ACK was lost.

Two possibilities when the child and parent run the code from the fork call()

1. The parent process ends before the child process 2.The child process ends before the parent process.

#include <stdio.h> #include <unistd.h> int main() { int i; for (i = 0; i < 4; i++) fork(); return 0; } Including the initial parent process, how many processes are created by the program here?

2^4, so 16 processes.

What are the benefits and the disadvantages of synchronous and asynchronous communication?

A benefit of symmetric communication is that it allows a rendezvous between the sender and receiver. At the programmer level, neither process has to block its execution which can result in better performance. The disadvantage of asymmetric communication is that blocking send is a rendezvous and may not be required and the message could be delivered asynchronously and received at a point of no interest to the sender. As a result, message-passing systems often provide both forms of synchronization. And it is more difficult to program since the programmer must guarantee that the message arrive at the receiver when it is needed. At the system level, asymmetric is more complicated since it required kernel-level buffering.

What are some complications with concurrency?

The operating system requires keeping track of all the storage space addresses on main memory to prevent one process from mixing with another or using the information stored for any other running process. Context switching between two simultaneous processes require enough time to locate and maintain register values for programs running. A continuous communication between operating system and program control block may overload the system. Process that requires big data blocks for execution may enter deadlocks in wait of getting resources freed up by other processes.

Using the program shown in Figure 3.30, explain what the output will be at LINE A. #include <sys/types.h> #include <stdio.h> #include <unistd.h> int value = 5; int main() { pid t pid; pid = fork(); if (pid == 0) { /* child process */ value += 15; return 0; } else if (pid > 0) { /* parent process */ wait(NULL); printf("PARENT: value = %d",value); /* LINE A */ return 0; } }

The output of this program at LINE A will be 5. The child process updates only its copy of value and after than control will be returned to parent process in which the value is 5 hence print statements will print the value as 5. Wait() is used in parent process hence firstly child will end then parents execute. Therefore final value will be from parent process.

Why would the execlp() function produce an error?

The reason for this may be absence of "bin/ls" or it might have been corrupted or no permission for its access.

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?

The server should keep a history of information and requests regarding the received RPC operations, a track of the successfully performed RPC operations, and the results affiliated to the operations, in stable storage like as a disk log. In this manner, whenever a server crashes and an RPC message is received, the server can verify whether the RPC had previously been executed or not and therefore guarantee "exactly once" semantics for the execution of RPCs.

What happens in situation 2? (2. The RPC was correctly received -and performed- by the server but the ACK was lost.)

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 that the RPC has been performed.

What happens in situation 1?? (1. The original RPC was never received by the server)

The use of ACKS allows the server ultimately to receive and perform the RPC.

Including the initial parent process, how many processes are created by the program shown in Figure 3.31? #include <stdio.h> #include <unistd.h> int main() { /* fork a child process */ fork(); /* fork another child process */ fork(); /* and fork another */ fork(); return 0; } How many parent processes and child processes will there be?

There are 8 processes created, because whenever a fork() function called, it creates processes as child nodes of a growing binary tree... i.e. 2^(whatever number of fork calls there are), so 2^3 = 8. There will be 1 parent process and 7 child processes.

What is the etc/init tab file?

This file is the initialization file for this process and commands the system about several to-do instructions on a program.

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.

When local procedure fails under extreme circumstances, RPC can fail, or be duplicated and executed more than once, as a result of network errors. In order to avoid this, time stamps are attached to each message. Therefore, the server must keep a history of all the time stamps of messages it has already processed or ensure that repeated message it has already processed are detected.

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)

At line A- it will print "child : pid = 0" (value returned by fork to child) At line B- it will print "child : pid1 = 2603" (actual pid of child) At line C- it will print "child : pid = 2603" (value returned by fork to parent) At line D- it will print "child : pid1 = 2600" (actual pid of parent)

What are the benefits and the disadvantages of automatic and explicit buffering?

Automatic buffering provides a queue with indefinite length. Thus, ensuring the sender will never have to block while waiting to copy a message. There are nos specifications how automatic buffering will be provided. One schema 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 i explicit buffering.

Describe what happens when a context switch occurs if the new context is already loaded into one of the register sets.

Context switch simply requires the CPU current-register-pointer to change to the register set containing the new context, which takes very little time

Describe long term scheduling. is it a CPU or job scheduler?

Determines which lobs 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.

Describe the role of exactly once with RPC mechanism.

Exactly once will remove the risk that the server will never receive the request. In order to complete this, the server must implement the "at most once" protocol as well as the acknowledgement should be provided to client that RPC was received and executed.

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

For "exactly once", we need to remove the risk that the server will never receive the request. To accomplish this, the server must implement the "at most once" protocol but must also acknowledge to the client that the RPC call was received and executed. The client must then resend each RPC call periodically until it receives the ACK for the call.

What does it do when the init process calls wait()?

Helps in collection of exit status of any orphaned child process and releasing its processID and process-able entries.

What happens if the new context is in memory rather than in a register set and all the register sets are in use?

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 where the new context is already on one of the register sets.

When are ordinary pipes more suitable than named pipes?

If we want to establish communication between two specific processes on the same machine, then using ordinary pipes is more suitable than using named pipes because named pipes involve more overhead i this situation. In this situation, where we will not allow access to our pipe after the communication is finished between processes using ordinary pipes is more suitable than named pipes.

When are named pipes more suitable than ordinary pipes?

Named pipes are more suitable than ordinary pipes when the medial is bidirectional, and there is no parent-child relationship between processes. Named pipes are more suitable than ordinary pipes in situations where we want to communicate over a network rather than communicating with the processes residing on the same machine. Named pipes can be used to listen to requests from other processes. If the calling processes are aware of the name, they can send requests to this. Unnamed pipes cannot be used for this purpose.

Does the init process call wait()?

Periodically

If the call returns in parent process, return value will be??

Process ID of child process

What happens with stacks and heaps when the fork function is called?

Stacks and heaps are not shared by these processes. Instead, new copies of the stack and the heap are made for the newly created process, when a process tries to write into these.

What are concurrent systems?

Systems which support the concept of executing more than one application or process at the same time. Here the processes running can either be a duplicate of each other or simply two different processes in all.

If wait() is called in some parent process then what?

That process will be suspended until child ends

What are the benefits and the disadvantages of 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). Fixed-sized messages are easier to implement at the kernel-level but require slightly more effort on the part of the programmer. Variable-sized messages are somewhat more complex for the kernel but somewhat easier for the programmer. The number of variable sized messages that can be help by such a bugger is unknown.

Explain the role of the init process on UNIX and Linux systems in regard to process termination. What is the first thing it does?

The initial thing an init process does on initialization is reading eh status of the etc/init tab file.

Give an example of send by copy and send by reference

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 use shared memory to pass the message.

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

c. Shared memory segments

Similar binding of ___ and ___ port is required for the RPC scheme.

client and server port

What happens if call returns in parent process?

if call returns in parent process, return value will be process id of child process.

What are the two processes created from fork()

parent and child processes

If process created successfully then the parent and child process will...

run the code from the same place where fork() call was running, due to duplicate memory.

Describe short term scheduling. Is it a CPU or job scheduler?

selects from jobs in memory those jobs that are ready to execute and allocates the CPU to them. CPU scheduler

Using the program shown in Figure 3.35, explain what the output will be at lines X and Y. #include <sys/types.h> #include <stdio.h> #include <unistd.h> #define SIZE 5 int nums[SIZE] = {0,1,2,3,4}; int main() { int i; pid t pid; pid = fork(); if (pid == 0) { for (i = 0; i < SIZE; i++) { nums[i] *= -i; printf("CHILD: %d ",nums[i]); /* LINE X */ } } else if (pid > 0) { wait(NULL); for (i = 0; i < SIZE; i++) printf("PARENT: %d ",nums[i]); /* LINE Y */ } return 0; }

the output a Line X would be: Child: 0 Child: -1 Child: -4 Child: -9 Child: -16 the output at line Y would be: Parent: 0 Parent: 1 Parent: 2 Parent: 3 Parent: 4

So how will the server perform the RPC operation "exactly once"

by combining ACK and timestamps.

How does the init process help restart processes?

by utilizing the "respawn action"

Explain the circumstances under which which the line of code marked printf("LINE J") in Figure 3.33 will be reached. #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; }

In main function, the first statement declares a variable pid of pid_t type to store the return value of the fork() function. After that, fork() function is called and stores its return value in pid variable. When value of variable pid becomes 0 then the condition statement esle if (pid == 0) is true. Now all of the statements inside this conditional are executed. After this execlp("/bin/ls","ls", NULL) function gets executed. The argument of this function contains the list of other executable files, if the file exist then that file execute otherwise returns a value of -1 which represent the error. If name of the file provided in the execlp() function does not exist then the line Printf("LINE J") gets executed. SO overall, an error in executing execlp() function would result in achieving the print command for the program.

What else does the init process do? (process termination hint)

Init process has role in process termination too. if the parent before calling the wait(), it makes the child an orphan. This case is handled in UNIX and LINUX systems by assigning init process.

Where are new processes (created from fork() call) created and loaded?

Into a separate memory location for the child processes by the operating system.

What is the "exactly once" procedure?

It is a semantic that ensures that a remote procedure will be executed exactly once.

What must be done in order for a client to receive the "ACK" for that call?

It must resend each RPC call periodically until it receives the "ACK" for that call?

What is saved by the kernel when switching between two processes? What is this method referred to as?

It saves the register values, memory address information, the program counter(PC) value, and the state of the current task in the PCB. this is also known as state save.

What happens if the client times out?

It simply assumes that the server was unable to perform the remote procedure so the client invokes the RPC a second time, sending a later timestamp.

What happens when a client sends a message more than once?

It will be executed only once.

Give an example of fixed-sized messages

Java's RMI (remote method invocation) provides passing a parameter by reference and requires declaring the parameter as a remote object as well.

What is a pro of concurrent systems?

Reduces overall execution time that may be required in executing a series of processes individually.

What happens if returns in child process?

Return value will be '0'.

What are the benefits and the disadvantages of send by copy and send by reference?

Send by copy is better for network generalization and synchronization issues. It does not allow the receiver to alter the state of the parameter, but send by reference allows it. Send by reference is more efficient for big data structures but harder to code because it allows the programmer to write a distributed version of a centralized application


Related study sets