Fichas
Inter process communication

Fichas del conjunto (40)
- 1What is the purpose of the fork() system call?To create an identical process. Becomes a "child" of the process that created it
- 2How many times does fork() return?Returns twice, one for the parent and one for the child
- 3Write a sequence of how it could look like when you call forkp = fork();
if (p==0) {
child process };
if (p>0) {
parent! the PID of the new child is returned. };
else {
parent, but child failed } - 4What is the purpose of the exit() system call?The child uses exit to terminate. The child may leave a status value (typically an integer) to its parent process to read later
- 5What actions must be taken by the kernel when exectuting the exit() system call?all of the memory and resources associated with the process are deallocated
- 6If an exit status is given to exit(), how is this information handled by the kernel?It is put in the PCB of the child
- 7How is exit() related to the "zombie" process state?If the child leaves an exit() code and the parent doesn't call wait() it is a zombie. The PCB of the child is still in memory
- 8wait() system callA parent process can use the wait() system call to suspend its execution until one of its children terminates and get the exit status of the terminated child.
- 9What are the possible return values of wait()?Returns ID of child process. Also returns exit status
- 10What is the purpose of the exec() family of system calls?A child may use the exec() sys call after a fork to replace the process memory space with a new program.
Any file descriptors open remains open after the call!
All data saved in the first process become lost. - 11If a parent process creates a pipe, then calls fork() and the child calls exec - will the child be able to access the pipe?No. If you replace the whole program the child can't listen from the other process
- 12What is the purpose of signals?Communication between processes. To tell each other that an event has occurred.
- 13What are the limitations of signals?They just tell the process what happened, not including exceptions or how you should handle the signal.
- 14What is a pipe?An array to use as communication between processes
- 15How are file descriptors used together with pipes?pipe() returns a pair of file descriptors referencing to the read and write ends of the pipe
- 16How do we create a pipe?int pdf[2];
pipe(pdf); - 17How can we make two processes share a pipe in order to communicate with each other?pipe()->fork(), or send pipe with exec()
- 181.What happens if we read from a pipe with no data? 2.What happens if we read from a pipe with no writers?1. You get blocked
2. You get an e.o.f code - 19What happens if we write to a full pipe? What happens if we write to pipe with no readers?1. Write is blocked
2. Sigpipe signal is used to notify writer when there is no reader -> process terminates - 20What is dup2() doing to file descriptors?dup2(int fild1, int fild2). Fild2 will point to the same file as fild1 after the call. fild1 remains open
- 21How can dup2() be useful?For example, if you wanted to redirect standard output to a file, then you would simply call dup2, providing the open file descriptor for the file as the first command and 1 (standard output) as the second command.
- 22What is meant by reentrant code?Can be interrupted and safely restarted
- 23A parent process calls srand() to seed the pseduo random generator (PRNG) and then uses fork() to create a number of child processes. Each child generates a sequence of "random" number by calling rand(). Can you make any predictions (motivate) about the sequences?The seed belongs to the process and fork copies it all -> same seed -> same numbers
- 24Context switchWhen CPU switches to another process. You must save the state of the old and load the state of the new via: context switch!
- 25Memory ; stack, heap and dataStack: temporary data such as function parameters, local variables
Heap: dynamically allocated during runtime
Data: global variables - 26Draw process scheduling

- 27Long term schedulerSelects program for ready q.
Controls the degree of multiprogramming
Executes less frequently (can take more time) - 28Short term scheduler-Selects which process should be executed next and allocates CPU.
- Works a lot -> must be fast - 29Examples of signalsSIGKILL - kill process
SIGTERM - request termination
SIGPIPE - notify writer when there is no longer a reader attached to the pipe - 30What is standard I/O stream?Pre-connected input and output communication channels between a program and its environment when it begins execution
- 31Which standard I/O-streams does POSIX define?stdin
stdout
stderr - 32What is a file descriptor?An abstrakt indicator used to access files or other I/O resources ( a non negative integer). The kernel keeps a table with info about a process open file descriptors. Stdin, stdout and stderr are by default open.
- 33open() and read()System calls used to open a file descriptor and then read from the file it is connected to.
You have to open before you read! - 34What can dup() be used for?Creates a copy of the file descriptor. One example use would be I/O redirection. For this you fork a child process and close the stdin or stdout file descriptors (0 and 1) and then you do a dup() on another filedescriptor of your choice which will now be mapped to the lowest available file descriptor, which is in this case 0 or 1.
- 35What is a problem with calling exec related to file descriptors?Since all data is erased in the process, any opened files can still be accessed, but the variabel holding the value of the file descriptor before the exec call does not exist!
- 36In short, explain what is meant by a blocking system call.A blocking system call is one that must wait until some action has ben completed by something other than the caller.
- 37Give an example of a Unix/Posix blocking system call together with a short explanation of why this system call may be blocking.read() - Reading from an empty pipe.
write() - Writing to a full pipe.
wait() - child has not yet terminated. - 38A system call might cause a context switch. T/F?TRUE
- 39In the context of CPU scheduling, in short, explain what is meant by the convoy effect.FCFS scheduling, Convoy
effect: short process(es) behind a long process leads to larger average waiting times. - 40What is the purpose of the WAIT state?When a process performs a blocking operation it leaves the RUNNING state and enters the WAIT state. This allows other processes to use the CPU while the process is blocked. When the process is no longer blocked it transiton from WAIT to READY.
Información
- Descripción
- Operating systems Fichas sobre Inter process communication , creado por Emma Tysk el 13/03/2017.
- Creado por
- Emma Tysk · mar 2017
- Actualizado
- 7 mar 2018
- Visitas
- 95
- Valoración