Slide 10-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10.

Slides:



Advertisements
Similar presentations
Processes Management.
Advertisements

Lab 9 CIS 370 Umass Dartmouth.  A pipe is typically used as a one-way communications channel which couples one related process to another.  UNIX deals.
Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.
Sockets Basics Conectionless Protocol. Today IPC Sockets Basic functions Handed code Q & A.
1 Java Networking – Part I CS , Spring 2008/9.
Process Process: the UNIX abstraction of a stand-along computer that manages resources (memory, CPU, I/O resources) comprising a running program. Processes.
Inter Process Communication:  It is an essential aspect of process management. By allowing processes to communicate with each other: 1.We can synchronize.
3.5 Interprocess Communication
CSE/EE 461 Getting Started with Networking. Basic Concepts  A PROCESS is an executing program somewhere.  Eg, “./a.out”  A MESSAGE contains information.
McGraw-Hill©The McGraw-Hill Companies, Inc., 2004 Application Layer PART VI.
Client Server Model The client machine (or the client process) makes the request for some resource or service, and the server machine (the server process)
Interprocess Communication. Process Concepts Last class.
Unix Processes Slides are based upon IBM technical library, Speaking Unix, Part 8: Unix processes Extended System Programming Laboratory (ESPL) CS Department.
Process-to-Process Delivery:
UNIX Signals Bach 7.2 Operating Systems Course The Hebrew University Spring 2010.
Agenda  Terminal Handling in Unix File Descriptors Opening/Assigning & Closing Sockets Types of Sockets – Internal(Local) vs. Network(Internet) Programming.
Chapter 9 Message Passing Copyright © Operating Systems, by Dhananjay Dhamdhere Copyright © Operating Systems, by Dhananjay Dhamdhere2 Introduction.
9/12/2015B.R1 Socket Abstraction and Interprocess Communication B.Ramamurthy CSE421.
Inter-Process Communication Mechanisms CSE331 Operating Systems Design.
Jozef Goetz, Application Layer PART VI Jozef Goetz, Position of application layer The application layer enables the user, whether human.
1 Version 3.0 Module 11 TCP Application and Transport.
Server Sockets: A server socket listens on a given port Many different clients may be connecting to that port Ideally, you would like a separate file descriptor.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Slide 9-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9.
Chapter 2 Applications and Layered Architectures Sockets.
The Socket Interface Chapter 21. Application Program Interface (API) Interface used between application programs and TCP/IP protocols Interface used between.
The Socket Interface Chapter 22. Introduction This chapter reviews one example of an Application Program Interface (API) which is the interface between.
Agenda  Working with Processes: Purpose Running Programs within same process (execl, execlp, execle, execv, execvp, execve) “Spawning” other process (fork,
1 Computer Networks An Introduction to Computer Networks University of Tehran Dept. of EE and Computer Engineering By: Dr. Nasser Yazdani Lecture 3: Sockets.
Distributed Computing A Programmer’s Perspective.
CE Operating Systems Lecture 13 Linux/Unix interprocess communication.
Unix Process Model Simple and powerful primitives for process creation and initialization. fork syscall creates a child process as (initially) a clone.
University of Calgary – CPSC 441.  A socket is an interface between the application and the network (the lower levels of the protocol stack)  The application.
CSE/EE 461 Getting Started with Networking. 2 Basic Concepts A PROCESS is an executing program somewhere. –Eg, “./a.out” A MESSAGE contains information.
Chapter 27 Socket API Interface The interface between an application program and the communication protocols in an operating system is known as the Application.
Processes CSCI 4534 Chapter 4. Introduction Early computer systems allowed one program to be executed at a time –The program had complete control of the.
Washington WASHINGTON UNIVERSITY IN ST LOUIS Core Inter-Process Communication Mechanisms (Historically Important) Fred Kuhns
Socket Programming Introduction. Socket Definition A network socket is one endpoint in a two-way communication flow between two programs running over.
UNIX signals & pipes. UNIX Signals A UNIX signal corresponds to an event –It is raised by one process (or hardware) to call another process’s attention.
Interprocess Communication Mechanisms. IPC Signals Pipes System V IPC.
Interprocess Communication Anonymous Pipes Named Pipes (FIFOs) popen() / pclose()
IPC in BSD UNIX Pipes –a pipe is an IPC mechanism for transmitting data from one process to another within a single machine –e.g., between a parent and.
2: Application Layer1 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP,
Signals & Message queue Inter process mechanism in Linux system 3/24/
InterProcess Communication. Interprocess Communication Processes within a system may be independent or cooperating Cooperating process can affect or be.
Inter-Process Communication 9.1 Unix Sockets You may regard a socket as being a communication endpoint. –For two processes to communicate, both must create.
S -1 Processes. S -2 wait and waitpid (11.2) Recall from a previous slide: pid_t wait( int *status ) wait() can: (a) block; (b) return with status; (c)
1 Lecture 19: Unix signals and Terminal management n what is a signal n signal handling u kernel u user n signal generation n signal example usage n terminal.
1 Network Communications A Brief Introduction. 2 Network Communications.
1 K. Salah Application Layer Module K. Salah Network layer duties.
SOCKET PROGRAMMING Presented By : Divya Sharma.
Socket Abstraction and Interprocess Communication
Operating Systems Review ENCE 360.
Sockets and Beginning Network Programming
Interprocess Communication
CGS 3763 Operating Systems Concepts Spring 2013
Socket Abstraction and Interprocess Communication
Operating Systems Lecture 12.
Socket Abstraction and Interprocess Communication
Socket Abstraction and Inter-process Communication
Inter-Process Communication ENCE 360
Socket Abstraction and Interprocess Communication
Interprocess Communication
Socket Abstraction and Interprocess Communication
Socket Abstraction and Interprocess Communication
Socket Abstraction and Interprocess Communication
Socket Abstraction and Inter-process Communication
Socket Abstraction and Inter-process Communication
Exceptions and networking
System Programming: Process Management
Presentation transcript:

Slide 10-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10

Slide 10-2 Copyright © 2004 Pearson Education, Inc. 2 Pipes Pipes are a way to allow processes to communicate with each other –Pipes implement one form of IPC (Interprocess Communication) –This allows synchronization of process execution There are two kinds of pipes –named pipes –unnamed pipes Pipes are uni-directional –They can only transfer data in one direction –If you want two processes to have a two-way conversation, you must use two pipes

Slide 10-3 Copyright © 2004 Pearson Education, Inc. 3 Pipes Implement a FIFO A FIFO (First In, First Out) buffer is like a queue or a line at a movie theater Elements are added at one end of the queue and exit the other end in the same order There is no way for any individual element to move ahead of another

Slide 10-4 Copyright © 2004 Pearson Education, Inc. 4 Traditional implementation of pipes uses the file system for storage –This allows processes to communicate even though they don’t know what processes are at the other end of the pipe Unnamed pipes can only be used between processes that are children of the process that initiated the pipe Named pipes solve this problem - any process can communicate with another using named pipes

Slide 10-5 Copyright © 2004 Pearson Education, Inc. Process tree and sharing pipes Operating Systems: A Modern Perspective, Chapter 10

Slide 10-6 Copyright © 2004 Pearson Education, Inc. 6 Unnamed Pipes Unnamed pipes are used as we saw in Unix cat myfile | grep key | sort | lpr The parent process (the shell or shell script that creates the pipes) also spawns the child processes that access the pipe –cat, grep, sort, and lpr in this case –Note: the shell or script process that sets up the pipes CANNOT access the pipes itself!

Slide 10-7 Copyright © 2004 Pearson Education, Inc. 7 Named Pipes Named pipes can be accessed by any process that “knows the name” Named pipes appear in the user’s directory list $ls -l pwr_r__r__ 1 krf 0 Mar 27 19:33 mypipe

Slide 10-8 Copyright © 2004 Pearson Education, Inc. 8 Named Pipe Creation Named pipes are created using the mknod or the mkfifo commands $mkfifo name $or mkfifo –m mode name $mknod name p Make sure you remove (rm) your pipes after use!

Slide 10-9 Copyright © 2004 Pearson Education, Inc. 9 Using Named Pipes First, create your pipes $mknod pipe1 p $mknod pipe2 p $mknod pipe3 p Then, attach a data source to your pipes $ls -l >> pipe1 & $cat myfile >> pipe2 & $who >> pipe3 & Then, read from the pipes with your reader process $cat < pipe1 | lpr $spell < pipe2 $sort < pipe3 oFinally, delete your pipes $rm pipe[1-3]

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 UNIX Pipes The pipe interface is intended to look like a file interface –Analog of open is to create the pipe –File read / write system calls are used to send/receive information on the pipe What is going on here? –Kernel creates a buffer when pipe is created –Processes can read/write into/out of their address spaces from/to the buffer –Processes just need a handle to the buffer

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 UNIX Pipes Info to be shared Info to be shared Info copy Address Space for p 1 pipe for p 1 and p 2 write function read function System Call Interface write(pipe[1], …);read(pipe[0]);

Slide Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 9 UNIX Pipes (cont) File handles are copied on fork … so are pipe handles int pipeID[2];... pipe(pipeID);... if(fork() == 0) { /* the child */... read(pipeID[0], childBuf, len); ;... } else { /* the parent */... write(pipeID[1], msgToChild, len);... }

Slide Copyright © 2004 Pearson Education, Inc. Code fragment: Named Pipes Char string[]=“Hello”; main(argc, argv) int argc; char* argv[]; int fd; char buf[256]; mknod(fifo”,010777,0) /* Create Pipe RW=all*/ if (argc==2) fd = open(“fifo”, 0_WRONLY; else fd = open(“fifo”, 0_RDONLY); for (;;) if (argc==2) write (fd, string, 6); else rd (fd, buf, 6);

Slide Copyright © 2004 Pearson Education, Inc. SOCKETS Operating Systems: A Modern Perspective, Chapter 10

Slide Copyright © 2004 Pearson Education, Inc. Why do we need sockets? Provides an abstraction for interprocess communication

Slide Copyright © 2004 Pearson Education, Inc. 6/4/2016 What are sockets? Socket is an abstraction for an end point of communication that can be manipulated with a file descriptor. It is an abstract object from which messages are sent and received. Sockets are created within a communication domain just as files are created within a file system. A communication domain is an abstraction introduced to bundle common properties of processes communicating through sockets. Example: UNIX domain, internet domain.

Slide Copyright © 2004 Pearson Education, Inc. Socket model Operating Systems: A Modern Perspective, Chapter 10

Slide Copyright © 2004 Pearson Education, Inc. A server accepting a call Operating Systems: A Modern Perspective, Chapter 10

Slide Copyright © 2004 Pearson Education, Inc. Functions –Define an “end- point” for communication –Initiate and accept a connection –Send and receive data –Terminate a connection gracefully Examples File transfer apps (FTP), Web browsers (HTTP), (SMTP/ POP3), etc…

Slide Copyright © 2004 Pearson Education, Inc. Sockets –a socket is an IPC mechanism for transmitting data from one process to another both within a single machine and between machines –a socket is a bi-directional IPC channel –Domains for sockets - a domain is the space from which an address is drawn for a socket UNIX domain(AF_UNIX) – uses the UNIX file system name space – used for local IPC Internet domain(AF_INET) – uses Internet address plus a port number – used for local and remote IPC

Slide Copyright © 2004 Pearson Education, Inc Types of Socket Stream sockets interface to the TCP (transport connect protocol). Datagram sockets interface to the UDP (user datagram protocol). Raw sockets interface to the IP (Internet protocol).

Slide Copyright © 2004 Pearson Education, Inc. Addresses, Ports and Sockets Like apartments and mailboxes –You are the application –Your apartment building address is the address –Your mailbox is the port –The post-office is the network –The socket is the key that gives you access to the right mailbox

Slide Copyright © 2004 Pearson Education, Inc. 6/4/2016 B.R 23 Sockets and ports message agreed port any port socket Internet address = Internet address = other ports client server

Slide Copyright © 2004 Pearson Education, Inc. Sockets used for streams Requesting a connectionListening and accepting a connection bind(s, ServerAddress); listen(s,5); sNew = accept(s, ClientAddress); n = read(sNew, buffer, amount) s = socket(AF_INET, SOCK_STREAM,0) connect(s, ServerAddress) write(s, "message", length) s = socket(AF_INET, SOCK_STREAM,0) ServerAddress and ClientAddress are socket addresses

Slide Copyright © 2004 Pearson Education, Inc. socket() bind() listen() accept() read() write() read() close() Socket() connect() write() read() close() TCP Client TCP Server Well-known port blocks until connection from client process request Connection establishment Data(request) Data(reply) End-of-file notification

Slide Copyright © 2004 Pearson Education, Inc. Server process in unix system Operating Systems: A Modern Perspective, Chapter 10

Slide Copyright © 2004 Pearson Education, Inc. A client process Operating Systems: A Modern Perspective, Chapter 10

Slide Copyright © 2004 Pearson Education, Inc. Definition : Signals A signal is an asynchronous event which is delivered to a process. Asynchronous means that the event can occur at any time –may be unrelated to the execution of the process –e.g. user types ctrl-C, when the system hangs 3/24/

Slide Copyright © 2004 Pearson Education, Inc. Linux Signals A LINUX signal corresponds to an event –It is raised by one process (or OS) to call another process’s attention to an event –It can be caught (or ignored) by the subject process 3/24/

Slide Copyright © 2004 Pearson Education, Inc. More on Signals UNIX has a fixed set of signals (Linux has 32 of them) signal.h defines the signals in the OS Each LINUX signal has an integer number and a symbolic name Defined in 3/24/

Slide Copyright © 2004 Pearson Education, Inc. 31 Signals Most signals have predefined meanings:  sighup (HangUp): when a terminal is closed, the hangup signal is sent to every process in control terminal.  sigint (interrupt): ask politely a process to terminate.  sigquit (quit): ask a process to terminate and produce a codedump.  sigkill (kill): force a process to terminate. 3/24/2011

Slide Copyright © 2004 Pearson Education, Inc. Signal Sources a process window manager shell command terminal driver memory management kernel other user processes SIGWINCH SIGKILL SIGINTSIGHUP SIGQUIT SIGALRM SIGPIPE SIGUSR1 3/24/

Slide Copyright © 2004 Pearson Education, Inc. Sending signals to process. (by keyboard) Ctrl-c This causes the system to send an INT signal (SIGINT) to the running process which causes The process to immediately terminates. Ctrl-z This causes the system to send an TSTP signal(SIGTSTP) to the running process this causes The process to Suspend execution. Ctrl-\ This is same as ctrl-c but with better flexibility This sends ABRT Signal (SIGABRT) 3/24/

Slide Copyright © 2004 Pearson Education, Inc. Signal transmission Signal Generation: The kernel updates data structure of the destination process to represent that a new signal has been sent Signal delivery: The kernel forces the destination process to react to the signal by changing its execution state, by starting the execution of a specified signal handler. The mechanics consist of two distinct steps: 34