Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

Chapter 3: Processes

Examples of IPC

Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018
Examples of IPC Systems - POSIX

• POSIX Shared Memory


• Process first creates shared memory segment

shm_fd = shm_open(name, O CREAT | O RDWR, 0666);
• Also used to open an existing segment
• Set the size of the object
• ftruncate(shm_fd, 4096);
• Use mmap() to memory-map a file pointer to the shared memory
object
• Reading and writing to shared memory is done by using the pointer
returned by mmap().


Operating System Concepts – 10th Edition 2 Silberschatz, Galvin and Gagne ©2018
IPC POSIX Producer

Operating System Concepts – 10th Edition 3 Silberschatz, Galvin and Gagne ©2018
IPC POSIX Consumer

Operating System Concepts – 10th Edition 4 Silberschatz, Galvin and Gagne ©2018
Examples of IPC Systems - producer–consumer problem using shared
memory

Operating System Concepts – 10th Edition 5 Silberschatz, Galvin and Gagne ©2018
Examples of IPC Systems – Windows

• Message-passing centric via advanced local procedure call


(LPC) facility
• Only works between processes on the same system
• Uses ports (like mailboxes) to establish and maintain
communication channels
• Communication works as follows:
! The client opens a handle to the subsystem’s connection
port object.
! The client sends a connection request.
! The server creates two private communication ports and
returns the handle to one of them to the client.
! The client and server use the corresponding port handle to
send messages and to listen for replies.

Operating System Concepts – 10th Edition 6 Silberschatz, Galvin and Gagne ©2018
Local Procedure Calls in Windows

two types of ports:


connec.on and communica.on

When an ALPC channel is created, one of three message-passing techniques is chosen:


1. For small messages (up to 256 bytes),
• the port’s message queue is used as intermediate storage,

2. Larger messages must be passed through a sec.on object,


3. When the amount of data is too large to fit into a sec.on object,
• an API is available that allows server processes to read and write directly into the address space of a client.

Operating System Concepts – 10th Edition 7 Silberschatz, Galvin and Gagne ©2018
Pipes
• Acts as a conduit allowing two processes to communicate
• Issues:
• Is communication unidirectional or bidirectional?
• In the case of two-way communication, is it half or full-duplex?
• Must there exist a relationship (i.e., parent-child) between the
communicating processes?
• Can the pipes be used over a network?
• Ordinary pipes – cannot be accessed from outside the process that
created it. Typically, a parent process creates a pipe and uses it to
communicate with a child process that it created.
• Named pipes – can be accessed without a parent-child relationship.

Operating System Concepts – 10th Edition 8 Silberschatz, Galvin and Gagne ©2018
Ordinary Pipes

• Ordinary Pipes allow communication in standard producer-consumer style


• Producer writes to one end (the write-end of the pipe)
• Consumer reads from the other end (the read-end of the pipe)
• Ordinary pipes are therefore unidirectional
• Require parent-child relationship between communicating processes

• Windows calls these anonymous pipes

Operating System Concepts – 10th Edition 9 Silberschatz, Galvin and Gagne ©2018
Named Pipes

• Named Pipes are more powerful than ordinary pipes


• Communication is bidirectional
• No parent-child relationship is necessary between the
communicating processes
• Several processes can use the named pipe for communication
• Provided on both UNIX and Windows systems

Operating System Concepts – 10th Edition 10 Silberschatz, Galvin and Gagne ©2018
Communications in Client-Server Systems/Sockets
• A socket is defined as an endpoint for communication

• Concatenation of IP address and port – a number included at


start of message packet to differentiate network services on a
host

• The socket 161.25.19.8:1625 refers to port 1625 on host


161.25.19.8

• Communication consists between a pair of sockets

• All ports below 1024 are well known, used for standard services

• Special IP address 127.0.0.1 (loopback) to refer to system on


which process is running

Operating System Concepts – 10th Edition 11 Silberschatz, Galvin and Gagne ©2018
Socket Communication

Operating System Concepts – 10th Edition 12 Silberschatz, Galvin and Gagne ©2018
Sockets in Java

• Three types of sockets


• Connection-oriented (TCP) using socket class
• Connectionless (UDP) using DatagramSocket class
• MulticastSocket class– data can be sent to multiple recipients using a subclass of
DatagramSocket

Operating System Concepts – 10th Edition 13 Silberschatz, Galvin and Gagne ©2018
Sockets in Java
• Consider this “Date” server in Java:

• a date server that uses connec.on-oriented TCP sockets.


• The opera.on allows clients to request the current date and .me from the server.
• The server listens to port 6013
• The server creates a ServerSocket that specifies it will listen to port 6013.
• The server then begins listening to the port with the accept() method.
• The server blocks on the accept() method wai.ng for a client to request a connec.on.
• When a connec.on request is received,
• accept() returns a socket that the server can use to communicate with the client.

Operating System Concepts – 10th Edition 14 Silberschatz, Galvin and Gagne ©2018
Sockets in Java
The Date client

• A client communicates with the server by crea.ng a socket and connec.ng to


the port on which the server is listening.
• The client creates a Socket and requests a connec.on with the server at IP
address 127.0.0.1 on port 6013
• the client can read from the socket using normal stream
• the client can read from the socket using normal stream

Operating System Concepts – 10th Edition 15 Silberschatz, Galvin and Gagne ©2018
End of Chapter 3

Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018

You might also like