CS149 Midterm1

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

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.

Which of the following is true in the context of Inter-process communication: A. It is like a user defined procedure call. B. It is like user defined a function call. C. It is a system call (provided by the kernel) D. None of the above

C) it is a system call provided by the kernel

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.

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

Does the init process call wait()?

Periodically

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.

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.

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.

A system call is a routine built into the kernel and performs a basic function. a) True b) False

True

Memory-mapped files may continue to exist in the system after the creating process has terminated. True False

True

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"

How many data structures does the kernel maintain in memory per process that contain information about an open file (based on the previous figure)? a) 3 b) 2 c) 5 d) 1

a) 3 file descriptor table the file table the vnode table

There are ___ distinct modes of opening a file. a) 9 (R, W, X and for users: owner, group, others) b) 4 (R, W, X) c) 2 (shared, private) d) 1

a) 9 (R, W, X and for users: owner, group, others) R, W, X = read, write, execute

What is the output of this program (syscalls/lseek1-2.c)? #include<stdio.h> #include<fcntl.h> int main() { int fd, count; char ch; fd = open("out.txt",O_RDWR|O_CREAT); write(fd,"s",1); lseek(fd,0,SEEK_SET); write(fd,"d",1); lseek(fd,0,0); read(fd,&ch,1); printf("%c\n",ch); return 0; } a) d b) s c) sd d) none of the mentioned

a) d

In the output of this program, the string "/* Linux */" will be added at the ____ of the source file #include<stdio.h> #include<stdlib.h> #include<fcntl.h> int main() { int fd; fd = open("src.c",O_RDWR|O_APPEND); write(fd,"/* Linux */",11); return 0; } a) end b) beginning c) second line d) third line

a) end

The vnode table is also called _____ a) inode table b) file table c) virtual table d) virtual ntable

a) inode table

A (hardware-generated) interrupt breaks the execution of instructions and diverts its execution to a) Interrupt handler routine b) Counter word register c) Execution unit d) control unit

a) interrupt handler routine

Which of the following statements is true? A) Memory mapping (mmap) allows bi-directional communication between processes. B) Only the parent and child processes can use memory mapping (mmap) for communication. C) Reading and writing to ordinary pipes on UNIX systems is performed exactly as in file I/O. D) Pipes/sockets can only be used by communicating processes on the same machine.

a) memory mapping (mmap) allows bi-directional communication between processes

All UNIX and LINUX systems have one thing in common which is ____ a) set of system calls (POSIX) b) set of commands c) set of instructions d) set of text editors

a) set of system calls (posix)

How does the OS communicate to an application process? a) Signals b) Bus c) Hardware interrupts d) Ethernet

a) signals

When we execute a C program, CPU runs in ____ mode. a) user b) kernel c) supervisory d) system

a) user

Which of the following offset is used with lseek system call to set the offset pointer relative to the end of the file? a) SEEK_SET b) SEEK_END c) SEEK_CUR d) SEEK_CR

b) SEEK_END

What is interprocess communication (IPC)? a) communication within the process b) communication between two process c) communication between two threads of same process d) none of the mentioned

b) communication between two process

What is the output of this program? #include<stdio.h> #include<fcntl.h> int main() { pid_t fd; char ch; int count; fd = open("src.c",O_RDONLY); do{ count = read(fd,&ch,1); printf("%c",ch); }while(count); return 0; } a) it will print nothing b) it will print the source code of the source file "src.c" c) segmentation fault d) none of the mentioned

b) it will print the source code of the source file "src.c"

In ____ mode, the kernel runs on behalf of the user. a) user b) kernel c) real d) all

b) kernel

What best describes a signal? a) any hardware device generated interrupt b) software or hardware generated event, mediated by kernel c) any interrupt always generated by a user d) none of the mentioned

b) software or hardware generated event, mediated by kernel

____ system call is used for writing to a file. a) read b) write c) close d) seek

b) write

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"

Choose the correct statements. A. C programs can directly make system calls B. Library functions can use system call C. Both (a) and (b) D. Library functions never use system calls

c) C programs can directly make system calls, Library functions can use system call

Which of the following system call is used for closing a file? a) open b) lseek c) close d) write

c) close

For IPC communication the OS employs an internally defined buffer data-structure, which is defined: a. In user space b. As a separate area which is neither in user space nor in kernel space c. In kernel space

c) in kernal space

Which of the following system call is used for opening or creating a file? a) read b) write c) open d) close

c) open

For reading input, which of the following system call is used? a) write b) rd c) read d) change

c) read

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 d. None of the above

c) shared memory segments

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

How does a user request a process to run in the foreground or background: a) Enter "fg" or "bg" command in the same terminal b) Run with the & suffix c) Send a 18/SIGCONT signal with kill -SIGCONT d) A or B

d) enter "fg" or "bg" command in the same terminal, run with the & suffix

Which of the following are true in the case of a pipe as a mechanism of IPC? a. A pipe is for uni-directional communication. b. A pipe uses a buffer and the size of the buffer can be specified by the user. c. Pipes can not support broadcast. d. All of the above

d) all of the above

write system call may return -1 when ___________ a) if disk fills up while write is in progress b) when file doesn't exist c) if the file size exceeds the system's limit d) All of these

d) all of the above

____ system call is used for positioning the offset pointer. a) read b) write c) open d) lseek

d) lseek

close system call returns ____ a) 0 b) -1 c) 1 d) 0 or -1

d) o or -1

Why shouldn't the output of a pipeline be produced using temporary files? a) pipes are implemented in RAM memory, which is faster than disk. b) with files would have to wait for a file to be completely written before next step c) programs can produce lots of I/O, so better to run them concurrently rather than wait for one to finish before starting the next one d) you might fill up the disk with large intermediate files or fill your inode quota with too many files e) all of these are reasons

e) all of the above

Run the code under Canvas code/ipc/parent_child_pipe.c. What does it do? a. It makes a pipe between 2 processes. b. It executes commands from the user in forked processes. c. Child sends a string to parent through a pipe. d. One process takes a string from stdin and sends it to the other process, which appends it to another string and prints it. e. Both a and c

e) it makes a pipe between 2 processes and child sends a string to parent through a pipe

a. It makes a pipe between 2 processes. b. It executes commands from the user in forked processes. c. It sends a string "hello world" from parent to child through a pipe. d. It pipes a given file through /bin/more, so the user can scroll through it. e. Both a and c

e) it makes a pipe between 2 processes, it sends a string "hello world" from parent to child through a pipe

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.

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

What is another name for a distributed version of centralized application

shared memory implications

Run the code under Canvas code/ipc/fork_pipe.c. What does it do? A. It makes a pipe between 2 processes. B. It executes commands from the user in forked processes. C. It sends a string from parent to child through a pipe. D. One process takes a string from stdin and sends it to the other process, which appends it to another string and sends it back to be printed. E. A, C and D

e) it makes a pipe between 2 processes, it sends a string from parent to child through a pipe, one process takes a string from stdin and sends it to the other process, which appends it to another string and sends it back to be printed

What happens if call returns in parent process?

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

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.

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.

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 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.

System calls and library functions are the same. a) True b) False

False

When a pipe is defined - its either end can be utilized freely for reading / writing a. True b. False

False

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.

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.

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

Process ID of child process

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

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 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.

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 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.

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.

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.

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.

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


Set pelajaran terkait

Chapter 3: Structure and Function of the Reproductive System

View Set

International Business Chapter 15jxhxhxhxh

View Set

Chapter 43: The Child with a Gastrointestinal Alteration McKinney: Evolve Resources for Maternal-Child Nursing, 5th Edition

View Set

Chapter 19- Investor Protection and Corporate Governance

View Set

Chapter 50: Disorders of Musculoskeletal System: Rheumatic Disorders

View Set

VDV: Applications and Installation (Part 1 of 3)

View Set