Module 2 - The process concept and IPC Flashcards
What is meant by a process?
An executable loaded into memory and executing or waiting. A
process typically executes for only a short time before it either finishes or needs to perform I/O (waiting). A process is an active entity and needs resources such as CPU time, memory etc to execute.
A process needs at least two critical resources, name these resources.
Each process must be allocated a
separate process memory image and a PCB in main memory (RAM).
CPU time.
Name and describe the various memory segments used by a process.
Stack: Temporary data such as function
parameters, local variables and return
addresses.
The stack grows from high addresses
towards lower address.
Heap: Heap: Dynamically allocated (malloc) by the program during runtime.
The heap grows from low addresses
towards higher addresses.
Data: Statically (known at compile time)
global variables and data structures.
Text: The program executable machine
instructions.
A process can be in different states. Name and explain the purpose of each such state.
New: A new process, the child process is created. The new child is a copy of its parent.
Ready: A “ready” process that is residing in main memory and is awaiting execution on a CPU.
Running: A process moves into the running state when it is chosen for execution. The process’s instructions are executed by one of the CPUs (or cores) of the system. There is at most one running process per CPU or core. A process can run in either of the two modes, namely kernel mode or user mode.
Waiting: A “waiting” process that is residing in main memory and is waiting for an I/O device.
Terminated: A process may be terminated, either from the “running” state by completing its execution or by explicitly being killed.
Draw a diagram showing how the process states are related using directed arrows showing possible state transitions.
Draw it.
What is the purpose of the PCB?
The process control block (PCB) is a data
structure in the operating system kernel
containing the information needed to
manage a particular process.
In brief, the PCB serves as the repository
for any information that may vary from
process to process.
Give examples of data stored in the PCB.
Process id (PID).
Process state (new, ready, running,
waiting or terminated).
CPU Context.
I/O status information.
Memory management information.
CPU scheduling information.
What is the purpose of the fork system call?
Fork is the primary (and historically, only) method of process creation on Unix-like operating systems.
What do we mean with parent and child?
The process calling fork() is called the parent.
The new process is called the child of the parent.
How many times does fork return?
On success, fork() return twice!
On failure, fork() returns -1 in the parent.
What are the possible return values of fork?
fork() in the parent returns either pid > 0 or -1.
fork() in the child returns 0.
After calling fork, how can the program know if it is executing in the parent or in the child?
fork() returns 0 if executing in the new child
process.
fork() returns pid > 0 if executing in the
parent process. It’s the process id (pid) of the child that is returned.
What is the purpose of the exit system call?
The child uses the exit() system call to
terminate.
What is the purpose of the exec family of system calls?
In Unix-like operating systems, the exec family of system calls runs an executable file in the context of an already existing process, replacing the previous executable.
When calling a function or invoking a system call, normally execution will return back to the caller, possible with a return value. Is this true for the exec family of system calls?
Justify your answer.
When a process calls exec, all code (text) and data in the process is lost and replaced with the executable of the new program. Although all data is replaced, all open file descriptors remains open after calling exec unless explicitly set to close-on-exec.
What is the purpose of the wait system call?
The parent may use the wait() system call to
wait for the child to terminate.
The wait() system call also makes it possible for the parent to get hold of the exit status of the terminated child.
What is the purpose of the zombie process state?
When does a process become a zombie?
A terminated process is said to be a zombie or defunct until the parent does wait() on the child.
Or in other words:
‣ When a process terminates all of the memory and resources associated with it are deallocated so they can be
used by other processes.
‣ However, the exit status is maintained in the PCB until the parent picks up the exit status using wait() and deletes the PCB.
What is the purpose of signals?
Signals are a limited form of inter-process communication used in Unix, Unix-like, and other POSIX-compliant operating systems.
‣ A signal is a notification sent to a process in order to notify it of an event that occurred.
What are the limitations of signals?
‣ Exceptions such as division by zero or a
segmentation violation will generate signals.
‣ Divison by zero will generate a SIGFPE signal.
‣ Segmentation violation will generate a SIGSEGV signal.
‣ If not explicitly caught, SIGFPE and SIGSEGV will cause a core dump and a program exit.
What happens when a process receives a signal?
‣ When a signal is sent, the operating system interrupts the target process’s normal flow of execution to deliver the signal.
‣ If the process has previously registered a signal handler, that routine is executed. Otherwise, the default signal handler is executed.
Explain the file descriptor concept.
In Unix and Unix-like computer operating systems, a file descriptor is an abstract indicator used to access a file or other input/output resource, such as a pipe or network socket.
What is a pipe?
An (anonymous) pipe is a simplex first-in first-out (FIFO) communication channel that may be used for one-way interprocess communication (IPC).
How are file descriptors used together with pipes?
We create read and writes end of a pipe using file descripors.
When using the pipe(pfd) system call, you create an array pfd were its elements are assigned descriptor numbers to that pipe.
This pipe object can now be accessed by any process that has the same file descriptors.
How do we create a pipe?
What is the result of creating a pipe?
In Unix-like operating systems pipes are created using the pipe() system call.
‣ As a result of the pipe() system call,
a pipe object is created.
‣ A pipe is a FIFO buffer that can be
used for inter process communication
(IPC).
‣ The pipe() system call returns a
pair of file descriptors referring to the
read and write ends of the pipe.