0% found this document useful (0 votes)
19 views11 pages

Understanding Operating System Processes

Uploaded by

Asif Rahman
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views11 pages

Understanding Operating System Processes

Uploaded by

Asif Rahman
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Chapter 3 :Processes

Zahirul Hoq Babor


Course: Operating Systems
Submission Date:
Instructor:Professor Farha Jahan
Department Of Computer Science and Engineering
University Of Chittagong

Contents

1 Questions and Answers 2

1
1. Questions and Answers
Q1: Question 1: What is process?what represent the status of current activity
of a process?
Answer: A process is a program in execution. The status of the current activity
of a process is represented by the value of the program counter and the contents of
the processor’s registers.

Q2: Question 2: Distinguish Between Process and Program?


Answer: A program by itself is not a process. A program is a passive entity, such
as a file containing a list of instructions stored on disk (often called an executable file
). In contrast, a process is an active entity, with a program counter specifying the
next instruction to execute and a set of associated resources. A program becomes a
process when an executable file is loaded into memory.

Q3: Question 3: Draw the Diagram of process state?


Answer: The diagram of process state is given below

Q4: Question 4: Define PCB(process control block)?


Answer: Each process is represented in the operating system by a process con-
trol block (PCB)—also called a task control block. The PCB simply serves as the
repository for all the data needed to start,or restart, a process, along with some
accounting data.A process block includes these following segments:

1. Process State

2. program counter

3. CPU registers

4. CPU scheduling information

5. memory management information

2
6. accounting information

7. I/O status information

Q5: Question 5:Describe process schedule in single core and multicore [Link]
is the degree of multiprogramming?
Answer: For a system with a single CPU core, there will never be more than one
process running at a time, whereas a multicore system can run multiple processes
at one time. If there are more processes than cores, excess processes will have to
wait until a core is free and can be rescheduled. The number of processes currently
in memory is known as the degree of multiprogramming.

Q6: Question 6: Define I/O bound process and CPU-bound process.


Answer: An I/O-bound process is one that spends more of its time doing I/O than
it spends doing computations. A CPU-bound process, in contrast, generates I/O
requests infrequently, using more of its time doing computations.

Q7: Question 7:What is CPU Scheduling?Why Do We Need CPU Schedul-


ing?
Answer: CPU scheduling is the method the operating system (OS) uses to decide
which process gets the CPU next.
Since the CPU is a limited resource, the OS ensures it is shared efficiently among
processes to maximize system [Link] need CPU Scheduling -

. To maximize CPU utilization (keep the CPU busy as much as possible).

. To share resources fairly between processes.

. To reduce waiting time for processes in the queue.

. To prioritize important tasks over less critical ones.

Q8: Question 8: Explain the CPU scheduling rules operating system uses.
Answer: The “Rules” the OS Uses

1. First-Come, First-Served (FCFS):


Serve processes in the order they arrive. Example: Customers line up, and the
barista serves the first one in line, even if the order is complex.

2. Shortest Job Next (SJN):


Serve the process with the shortest CPU burst time. Example: The barista chooses
to make the simplest drink first to clear orders quickly.

3. Round Robin (RR):


Each process gets a small, fixed time slice on the CPU, then moves to the back of
the line. Example: The barista works on each customer’s order for 5 minutes, then
moves to the next one.

4. Priority Scheduling:
Serve the process with the highest priority first. Example: A VIP customer gets
their order made before others, even if they came later.

3
5. Multilevel Queue:
Divide processes into groups (e.g., system tasks, user tasks) and assign different
scheduling rules to each group. Example: A barista might prioritize regular cus-
tomers but serve kids in a special ”express line.”

6. Multilevel Feedback Queue:


Like Multilevel Queue, but processes can move between queues based on behavior
(e.g., long wait times). Example: If a regular customer waits too long, they might
get bumped to the VIP line.

Q9: Question 9:What is a Context Switch?Why Do We Need Context Switches?

Answer: A context switch happens when the operating system (OS) changes the
currently running process to another one. It ensures that multiple processes can
share the CPU (especially in multitasking environments).Why need context-switch–

1. The CPU can only work on one process at a time.

2. To create the illusion of multiple processes running simultaneously, the

3. OS rapidly switches between processes. Example: While you’re watching a video, a


browser process might be running in the background downloading data.

Q10: Question 10:Why Do Processes Get Created?How is a Process Cre-


ated?Describe Parent-Child Processes in UNIX/Linux.
Answer:

1. System Initialization:
When the OS starts, it creates system processes for basic operations (e.g., managing
I/O or background tasks).

2. User Request:
A user launches a program, like opening a browser or a text editor.

3. Parent-Child Relationship:
A process can create new processes to perform specific tasks. The original process
is called the parent, and the new one is the child.

4. Batch Jobs or Scripts:


The OS may create processes to execute batch jobs or automated tasks.
How a process is created:

1. Parent Process Decides to Create:


A running process (parent) decides to create a child process using a system call like
fork() (in UNIX-based systems).

2. Allocate Resources:
The OS allocates memory, CPU time, and other resources to the new process.

4
3. Initialize PCB:
A Process Control Block (PCB) is created for the new process. PCB stores process
metadata like ID, state, priority, and memory information. Copy or Share Data:

4. The child process may: Share the parent’s memory and data. Or get a copy of it,
depending on the system.

5. Execution Begins:
The OS decides when the child process gets CPU time.
**Parent-Child Processes in UNIX/Linux: In UNIX/Linux, the common way
to create a process is:

1/ fork():
Creates a duplicate of the parent process. The child process is identical but has a
unique Process ID (PID).

2/ exec():
Replaces the child process’s memory with a new program. For example, a parent
process can use fork() to create a child, and then the child runs a specific program
using exec().

Q11: Question 11: What is process termination?How Does Process Termina-


tion Happen?Define Cascading Termination,wait() System Call,Zombie
Process,Orphan Process,Init Process.
Answer: A process terminates when it finishes execution or is explicitly killed.
Termination is the final step in a process’s life cycle.
How does process Termination occur:
[Link] Completion:
The process finishes its task and exits using system calls like exit().
Example: A program ends after printing ”Hello, World!”
[Link] Exit:
The process terminates due to an error (e.g., division by zero).
[Link] by Another Process:
Another process (usually the parent) can terminate it using system calls like kill().
[Link] Constraints:
The OS terminates a process if it exceeds resource limits (e.g., memory or CPU
usage).
Cascading Termination:
When a parent process terminates, its child processes may also terminate automat-
ically. This is known as cascading termination.
Reason: The parent may be responsible for its children, so the OS ensures no or-
phaned processes are left running. Example:If a parent process running a web server
terminates, its child processes handling client requests might also terminate.

wait() system call:The wait() system call is used by a parent process to wait for
one of its child processes to terminate.

5
How Does wait() Work?
[Link] blocks the parent process until a child terminates.
[Link] the child process terminates,The parent collects the child’s exit status and
The child’s entry is removed from the process table, preventing it from becoming a
zombie.
Zombie process:
A zombie process is a process that has completed execution but still exists in the
process table.
Why Does This Happen?
[Link] a child process finishes, it sends an exit status to the parent.
[Link] the parent doesn’t call wait() or waitpid() to collect the status, the process re-
mains in the process table as a zombie.
Key Points:
1.A zombie process consumes no resources except for its entry in the process table.
[Link] many zombie processes can exhaust the process table, preventing new pro-
cesses from being created.
How to Avoid Zombie Processes: The parent should always call wait() or wait-
pid() to clean up terminated child processes.
Orphan Process:
An orphan process is a child process whose parent has terminated before it finishes.
What Happens to Orphans?
[Link] OS reassigns orphaned processes to the init process (PID 1).
[Link] init process ”adopts” orphans and cleans them up after they terminate, pre-
venting them from becoming zombies
init Process:
The init process is the first process started by the kernel when the system boots. It
has PID 1 and is the ancestor of all processes on the system.

Q12: Question 12:What is Interprocess Communication (IPC)? Why Do We


Need IPC?
Answer: Interprocess Communication (IPC) allows processes to exchange data and
coordinate their actions. Since processes often run independently, IPC provides a
mechanism for them to share information when needed.
why we need ——————
Data Sharing: Processes need to share data (e.g., a web server and a database
process).
Synchronization: To ensure processes don’t interfere with each other when ac-
cessing shared resources.
Modularity: Dividing tasks into multiple processes that need to communicate for
overall functionality.

Q13: Question 13:Describe Communications Models in IPC .Shared-memory


and message passing [Link] to use each?
Answer:
Shared Memory Model:

[Link] share a region of memory to communicate.

6
[Link] process can directly read/write data in the shared memory.
[Link] because no kernel intervention is needed during the actual data transfer.
[Link] synchronization mechanisms (e.g., semaphores or mutexes) to avoid race
conditions.
How Shared Memory Works:
1.A shared memory segment is created by one process.
[Link] processes attach to this shared memory segment.
[Link] read/write data directly in the shared memory region.

Advantages:
Fast: Data doesn’t need to be copied between processes.
Efficient for Large Data: Ideal for high-throughput applications like video stream-
ing.
Disadvantages:
Requires Synchronization: Processes can overwrite each other’s data if not properly
synchronized.
Complexity: Managing shared memory and synchronization is more challenging than
message passing.

Message Passing Model:


[Link] communicate by sending and receiving messages.
[Link] operating system acts as an intermediary, ensuring data integrity and syn-
chronization.
[Link] to implement in distributed systems where processes may run on different
machines.
[Link] than shared memory due to kernel overhead.

How Message Passing Works:


1.A process sends a message to another process through the operating system.
[Link] OS stores the message in a queue until the recipient process retrieves it.
Advantages:
Synchronization is Built-in: No need for manual locks.
Distributed Systems: Works seamlessly for processes on different machines.
Decoupled Processes: Processes don’t need to share memory.
Disadvantages:
Slower: Kernel involvement adds overhead.
Data Size Limits: Messages are typically limited in size.

When to Use Each:


shared Memory: High-speed, large data applications on the same machine.
Message Passing: Easier to use, especially for distributed systems or when syn-
chronization is needed.

Q14: Question 14:What is Synchronization ? What is Buffering?


Answer: Synchronization ensures that processes access shared resources or com-
municate in a coordinated way to avoid conflicts.

7
Buffering
Buffering refers to how data is temporarily stored during communication between
processes.

Why Buffering is Important?


Matches the speed differences between communicating processes.
Allows asynchronous communication (processes don’t have to run simultaneously).
Buffering Levels
[Link] Capacity (No Buffer):

The sender must wait until the receiver is ready to accept the message. Also called
synchronous communication.
[Link] Buffer:
The buffer has a limited size. If the buffer is full, the sender must wait. If the buffer
is empty, the receiver must wait. Example: Producer-Consumer problem where a
producer adds items to a fixed-size buffer, and a consumer removes them.

[Link] Buffer:

The buffer can grow dynamically to accommodate any number of messages. Rare
in practice due to memory constraints.

*Buffering in Message Passing


Kernel-Managed Buffers: Messages are stored in the kernel until the receiver re-
trieves them. User-Managed Buffers: Shared memory regions managed directly by
the processes.

Q15: Question 15:What is pipe and its type?


Answer: A pipe acts as a conduit allowing two processes to communicate. Pipes
were one of the first IPC mechanisms in early UNIX systems. They typically provide
one of the simpler ways for processes to communicate with one another, although
they also have some limitations.
Two common forms of client–server communication are sockets and remote proce-
dure calls (RPCs). Sockets allow two processes on different machines to commu-
nicate over a network. RPCs abstract the concept of function (procedure) calls in
such a way that a function can be invoked on another process that may reside on a
separate computer

Q16: Question 16: Briefly explain some IPC syestem of OS like POSIX,WINDOWS,PIPES
MASSAGING syestem.
Answer: Inter-Process Communication (IPC) systems enable processes to exchange
data and synchronize their actions in an operating system. Here’s a brief explana-
tion of the mentioned IPC mechanisms:

POSIX (Portable Operating System Interface):


POSIX provides standardized IPC mechanisms widely used in Unix-like systems.

8
Key IPC features include:

Shared Memory: Processes share a region of memory for fast data exchange.
Message Queues: Queues store messages for processes to retrieve asynchronously.
Semaphores: Used for synchronization and controlling access to shared resources.
Windows IPC:
Windows operating systems offer various IPC methods:

Named Pipes: Allow communication between processes on the same or different


machines.
Shared Memory (File Mapping): Processes map a file into memory for shared access.
Mail Slots: Enable one-way communication where multiple clients send messages to
a single server.
COM (Component Object Model): A higher-level mechanism for communication
between objects.

Pipes:
Pipes are simple, unidirectional communication channels commonly used in Unix-
like systems:

Anonymous Pipes: Used for communication between parent and child processes.
Named Pipes: Provide bidirectional communication and can be used between unre-
lated processes.

Mach Messaging (Microkernel IPC):


The Mach microkernel uses a message-passing mechanism as its primary IPC method:

Messages: Encapsulate data exchanged between tasks.


Ports: Act as communication endpoints, allowing tasks to send and receive mes-
sages.
Port Sets: Allow grouping of multiple ports for efficient management.

Each of these mechanisms is tailored for specific use cases, balancing performance,
complexity, and flexibility.

Q17: Question 17:What is [Link] Sokets works?


Answer: Sockets are low-level communication endpoints used to establish a con-
nection between client and server.

How Sockets Work:


[Link] Creation:
Server creates a socket and binds it to an IP address and port number.
The client creates its own socket to connect to the server’s address and port.

9
[Link] Establishment:
The server listens for incoming client connections using a ”listening socket.”
The client initiates the connection, and the server accepts it.

[Link] Exchange:
After the connection is established, the client and server send and receive data
through the sockets using TCP (reliable) or UDP (faster, but less reliable).

[Link]:
Either side can close the connection when communication is complete.

Q18: Question 18:What is RPCs(Remote producer Calls)?How RPCs works?


Answer:RPC is a higher-level abstraction that allows a program to execute a pro-
cedure (function) on a remote server as if it were local.//
How RPC Works:

[Link] Stub:
The client calls a local ”stub” function representing the remote procedure.
The stub prepares the request by marshaling (serializing) arguments.

[Link] Communication:
The request is sent to the server over the network.

[Link] Stub:
The server stub receives the request, unmarshals the arguments, and invokes the
actual procedure on the server.

[Link]:
The result of the procedure is marshaled and sent back to the client, where it is
unmarshaled by the client stub.

Q19: Question 19:Comparison Between Sokets and RPCs.


Answer: Comparison Between Sokets and RPCs is given below:

Feature ================ Sockets ================ RPC


Level of Abstraction=====Low (raw data exchange) ====== High (function
calls)
Complexity ====== Requires managing connections,data ===== Simplifies re-
mote interaction
Performance==== Faster (no marshaling overhead)====Slightly slower (due to
marshaling)
Ease of Use ======= Complex ======= Simple with a suitable framework
Use Case===Real-time apps, custom protocols ====Microservices, distributed
systems˙

10
Both sockets and RPCs are powerful tools for client-server communication. Sockets
provide fine-grained control, while RPCs prioritize simplicity and abstraction.

Q20: Question 20: Give an example of a situation in which ordinary pipes are
more suitable than named pipes and an example of a situation in which
named pipes are more suitable than ordinary pipes.
Answer: Ordinary Pipes:

Definition: Ordinary (or unnamed) pipes provide a unidirectional communication


channel between a parent and child process. They require a common ancestry.

Named Pipes:
Definition: Named pipes (also called FIFOs) are more versatile. They allow bidi-
rectional communication between unrelated processes and persist beyond the lifetime
of the processes.
Example Scenarios: 1. Ordinary Pipes:
Suitable Scenario: Communication between a parent and child process in the
same program.
Example:
A program spawns a child process to handle a specific task and communicates with
it through a pipe.
Use Case: A shell executing a command like ls — grep ”.txt”:
The parent process (ls) sends its output to the pipe.
The child process (grep) reads the output from the pipe.
Why Suitable?
Ordinary pipes are simple and efficient for short-lived communication between pro-
cesses with a parent-child relationship.

2. Named Pipes:
Suitable Scenario: Communication between unrelated processes or processes run-
ning at different times.
Example:
A logging system where one process writes log messages to a pipe, and another pro-
cess reads and processes those messages.
Use Case: A server application writes to a named pipe, and a separate monitoring
tool reads from it to display logs in real time.
Why Suitable?
Named pipes allow unrelated processes to communicate, and their persistence makes
them useful for applications that need IPC beyond the lifetime of any single process.

11

You might also like