Docsity

Inter Process Communication - Lecture Slides | CSC 1600, Study notes of Operating Systems

Partial preview of the text

Download Inter Process Communication - Lecture Slides | CSC 1600 and more Study notes Operating Systems in PDF only on Docsity!

CSC 1600 – Operating Systems

InterProcess Communication

Slides by Tanenbaum, Modern Operating Systems 3e, slightly modified by M. Damian

Overview

‰ Communication between processes

‰ Pipe between two processes

‰ Redirecting stdin and stdout

Communication Between Processes

different machines

same machine

Interprocess Communication

‰ Pipes

‰ Processes on the same machine ‰ One process spawns the other ‰ Used mostly for a pipeline of filters

‰ Sockets

‰ Processes on any machines ‰ Processes created independently ‰ Used for client/server communication (e.g., Web)

Both provide abstraction of an “ordered stream of bytes.”

Creating a Pipe

Pipe between Parent and Child

‰ Parent creates a pipe, then forks a child

‰ Child inherits the file descriptor table (and so the pipe)

‰ Pipe is used between parent and child in one direction

Parent fd[0] fd[1]

pipe OS

Child fd[0] fd[1]

File Descriptor Tables

0 read 1 write 2 write 3 4 ...

Parent process file descriptor table

‰ Fork duplicates the descriptor table ‰ Open/close/pipe etc. modify the table

Child process file descriptor table read 0 write 1 write 2 3 4 ...

write

pipe buffer amount held room left

fork

pipe

write read 4

data blocks data blocks data blocks ...

open

Pipe Example

child

parent

Dup2 Illustrated

‰ dup2 duplicates a file descriptor value

‰ As a result, fd2 will refer to the same file as fd

dup2(fd, fd2);

File descriptor data

Process file descriptor table before ... and after dup2(fd, fd2)

File descriptor data

0 1 ...^2 fd2 null

fd

0 1 ...^2 fd

fd

Pipes and Stdio

child makes stdin (0) the read side of the pipe

parent makes stdout (1) the write side of the pipe

Pipes and Exec

child process

invokes a new program

UNIX Shell Revisited

‰ A shell is mostly a big loop

‰ Parse command line from stdin ‰ Expand wildcards (‘*’) ‰ Interpret redirections (‘|’, ‘<‘, and ‘>’) ‰ Pipe, fork, dup, exec, and wait, as necessary

‰ Start from the code online and on slides

‰ And edit till it becomes a UNIX shell

Conclusion

‰ System calls for inter-process communication

‰ Pipe: create a pipe with a write end and a read end

‰ Open/close: to open or close a file

‰ Dup2: to duplicate a file descriptor