Top Banner
IPC INTERPROCESS COMMUNICATION By.Prof.Ruchi Sharma 06/22/22 1
21
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Ipc ppt

IPCINTERPROCESS COMMUNICATION

By.Prof.Ruchi Sharma

04/12/23 1

Page 2: Ipc ppt

Many operating systems provide mechanisms for interprocess communication (IPC)Processes must communicate with one another in

multiprogrammed and networked environments For example, a Web browser retrieving data from a

distant serverEssential for processes that must coordinate

activities to achieve a common goal.

04/12/23 2

Page 3: Ipc ppt

Software interrupts that notify a process that an event has occurredDo not allow processes to specify data to exchange

with other processesProcesses may catch, ignore or mask a signal

Catching a signal involves specifying a routine that the OS calls when it delivers the signal

Ignoring a signal relies on the operating system’s default action to handle the signal

Masking a signal instructs the OS to not deliver signals of that type until the process clears the signal mask

04/12/23 3

Page 4: Ipc ppt

Message-based interprocess communicationMessages can be passed in one direction at a time

One process is the sender and the other is the receiverMessage passing can be bidirectional

Each process can act as either a sender or a receiverMessages can be blocking or nonblocking

Blocking requires the receiver to notify the sender when the message is received

Nonblocking enables the sender to continue with other processing

Popular implementation is a pipe A region of memory protected by the OS that serves as a

buffer, allowing two or more processes to exchange data

04/12/23 4

Page 5: Ipc ppt

UNIX processesAll processes are provided with a set of memory

addresses, called a virtual address spaceA process’s PCB is maintained by the kernel in a

protected region of memory that user processes cannot access

A UNIX PCB stores: The contents of the processor registers PID The program counter The system stack

All processes are listed in the process table

04/12/23 5

Page 6: Ipc ppt

UNIX processes continuedAll processes interact with the OS via system

callsA process can spawn a child process by using the

fork system call, which creates a copy of the parent process Child receives a copy of the parent’s resources as well

Process priorities are integers between -20 and 19 (inclusive) A lower numerical priority value indicates a higher

scheduling priorityUNIX provides IPC mechanisms, such as pipes, to

allow unrelated processes to transfer data

04/12/23 6

Page 7: Ipc ppt

04/12/23 7

Figure 3.10 UNIX system calls.

Page 8: Ipc ppt

Outline4.1 Introduction4.2 Definition of Thread

4.3 Motivation for Threads

4.4 Thread States: Life Cycle of a Thread

4.5 Thread Operations

4.6 Threading Models

4.6.1 User-Level Threads

4.6.2 Kernel-Level Threads

4.6.3 Combining User- and Kernel-Level Threads

4.7 Thread Implementation Considerations

4.7.1 Thread Signal Delivery

4.7.2 Thread Termination

4.8 POSIX and Pthreads

4.9 Linux Threads

4.10 Windows XP Threads

4.11 Java Multithreading Case Study, Part 1: Introduction to Java Threads

04/12/23 8

Page 9: Ipc ppt

After reading this chapter, you should understand: the motivation for creating threads. the similarities and differences between processes

and threads. the various levels of support for threads. the life cycle of a thread. thread signaling and cancellation. the basics of POSIX, Linux, Windows XP and Java

threads.

04/12/23 9

Page 10: Ipc ppt

General-purpose languages such as Java, C#, Visual C++ .NET, Visual Basic .NET and Python have made concurrency primitives available to applications programmer

MultithreadingProgrammer specifies applications contain threads

of executionEach thread designate a portion of a program that

may execute concurrently with other threads

04/12/23 10

Page 11: Ipc ppt

ThreadLightweight process (LWP)Threads of instructions or thread of controlShares address space and other global information

with its processRegisters, stack, signal masks and other thread-

specific data are local to each thread Threads may be managed by the operating

system or by a user application Examples: Win32 threads, C-threads, Pthreads

04/12/23 11

Page 12: Ipc ppt

Figure 4.1 Thread Relationship to Processes.

04/12/23 12

Page 13: Ipc ppt

Threads have become prominent due to trends in Software design

More naturally expresses inherently parallel tasks

Performance Scales better to multiprocessor systems

Cooperation Shared address space incurs less overhead than

IPC

04/12/23 13

Page 14: Ipc ppt

Each thread transitions among a series of discrete thread states

Threads and processes have many operations in common (e.g. create, exit, resume, and suspend)

Thread creation does not require operating system to initialize resources that are shared between parent processes and its threadsReduces overhead of thread creation and

termination compared to process creation and termination

04/12/23 14

Page 15: Ipc ppt

Figure 4.2 Thread life cycle.

04/12/23 15

Page 16: Ipc ppt

User-level threads perform threading operations in user space Threads are created by runtime libraries that cannot

execute privileged instructions or access kernel primitives directly

User-level thread implementation Many-to-one thread mappings

Operating system maps all threads in a multithreaded process to single execution context

Advantages User-level libraries can schedule its threads to optimize

performance Synchronization performed outside kernel, avoids context

switches More portable

Disadvantage Kernel views a multithreaded process as a single thread of control

Can lead to suboptimal performance if a thread issues I/O Cannot be scheduled on multiple processors at once

04/12/23 16

Page 17: Ipc ppt

Figure 4.3 User-level threads.

04/12/23 17

Page 18: Ipc ppt

Kernel-level threads attempt to address the limitations of user-level threads by mapping each thread to its own execution contextKernel-level threads provide a one-to-one thread

mapping Advantages: Increased scalability, interactivity, and throughput Disadvantages: Overhead due to context switching and

reduced portability due to OS-specific APIs

Kernel-level threads are not always the optimal solution for multithreaded applications

04/12/23 18

Page 19: Ipc ppt

Figure Kernel-level threads.

04/12/23 19

Page 20: Ipc ppt

The combination of user- and kernel-level thread implementation Many-to-many thread mapping (m-to-n thread mapping)

Number of user and kernel threads need not be equal Can reduce overhead compared to one-to-one thread mappings by

implementing thread pooling Worker threads

Persistent kernel threads that occupy the thread pool Improves performance in environments where threads are

frequently created and destroyed Each new thread is executed by a worker thread

Scheduler activation Technique that enables user-level library to schedule its

threads Occurs when the operating system calls a user-level

threading library that determines if any of its threads need rescheduling

04/12/23 20

Page 21: Ipc ppt

Figure 4.5 Hybrid threading model.

04/12/23 21