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.