In: Computer Science
Please briefly explain the answer and why.
(1) What are the differences between a process and a thread? Explain in perspectives of memory sharing, switching, communication, etc.
(2) In inter-process communication using message passing, there are
two types of send/receive operations: blocking send/receive
and non-blocking send/receive. What is the difference
between the two approaches? Explain how the operations will behave
when called.
(3) When a process is created, memory is allocated for the process.
Describe each section of the memory allocated to the
process, and what goes into each section.
Ans-(1)Definition-A process is a program under execution i.e an active program and a thread is a lightweight process that can be managed independently by a scheduler.
a)Memory Sharing-A process has its own address space where as a thread uses the process’s address space and shares it with the other threads of that process.
b)Context switching time-Processes require more time for context switching as they are heavier on the other hand Threads require less time for context switching as they are lighter than processes.
c)Communication-Communication between processes requires more time than between threads but Communication between threads requires less time than between processes.
d)Resource Consumption-Processes require more resources than threads but Threads generally need less resources than processes.
Ans-(2)Interprocess Communication-
Interprocess communication refers to the exchange of information between separate threads or processes. There are two basic models of interprocess communication. Information can be exchanged by utilising a shared region of memory between the communicating parties or by using explicit message passing primitives.
The message passing operations Send and Receive may be either blocking or non-blocking.
Blocking Send: Sending process is blocked until the message passing mechanism has delivered the message to the receiving process or to a mailbox.
Non-Blocking Send: The sending process sends a message and can continue other tasks immediately while the message passing mechanism delivers the message.
Blocking Receive: Receiver waits until a message is received by it.
Non-Blocking Receive: Receiver either gets an available message or a null value returned by the Receive primitive.
Ans-(3) When a program is loaded into the memory and it becomes a process, it can be divided into four sections ─ stack, heap, text and data. The attached image shows a simplified layout of a process inside main memory .
Component & Description:
Stack-The process Stack contains the temporary data such as method/function parameters, return address and local variables.
Heap-This is dynamically allocated memory to a process during its run time.
Text-This includes the current activity represented by the value of Program Counter and the contents of the processor's registers.
Data-This
section contains the global and static variables.