49 InterProcess Communication IPC Signal Pipe Socket Section

  • Slides: 13
Download presentation
49 Inter-Process 장 Communication IPC Signal Pipe Socket

49 Inter-Process 장 Communication IPC Signal Pipe Socket

Section 01 IPC Inter-process communication Processes exchange data for various reasons. Data size varies.

Section 01 IPC Inter-process communication Processes exchange data for various reasons. Data size varies. Processes may be in the same system or in different systems. The processes may be user processes and/or system kernel. Should choose a proper communication method. signal, pipe, socket 2

Section 02 01 Signal delivered to processes when specific events happen. Computation errors, exit

Section 02 01 Signal delivered to processes when specific events happen. Computation errors, exit of a child process, halt request from the user etc. Usually a very small data. Sometimes called as “interrupt”. There are many signals and each one of them has unique number. Within a program, we use Macro Constant for the signals. ex) Pressing Ctrl + C deliver the signal, SIGTERM, to the process. When you issue kill command the SIGTERM is delivered to the process. 3

Section 02 01 Signal Process reaction upon receiving a signal 1. Default reaction for

Section 02 01 Signal Process reaction upon receiving a signal 1. Default reaction for signal. Most signal causes a process to exit. 2. Ignore the signal. But SIGKILL and SIGSTOP cannot be ignored. 3. Execute the function designated by the programmer. Signal handler Function to be executed when a process receives a specific signal. The process execute the corresponding signal handler when it receives a specific signal. At the end of the signal handler, the process resumes. Signals "/usr/include/asm/signal. h" 4

Section 02 01 Signal Ex : Simple way to send a signal to a

Section 02 01 Signal Ex : Simple way to send a signal to a process By pressing [Ctrl + C] or [Ctrl + Z], we can send the SIGINT or SIGSTP to the foreground process. What are the reactions for the two signals? 5

Section 03 01 Pipe IPC that has been used and supported by kernel. The

Section 03 01 Pipe IPC that has been used and supported by kernel. The stdout of the process in front of a pipe (|) is fed into the stdin of the process that is right behind the pipe. Pipe is a file. Pipe is a special form of a file and becomes a medium of IPC. The process in front of the pipe can only write while the process behind the pipe only reads. There anonymous pipe, named pipe and FIFO. 6

Section 03 01 Pipe Anonymous pipe $ ls $ / | wc -w 20

Section 03 01 Pipe Anonymous pipe $ ls $ / | wc -w 20 -l / | wc -l 20 A pipe is created to execute the command. The pipe will be destroyed when the command finishes. As it is created for the execution of a command destroyed after that. It is not named and hard to verify. In this example, “ls” only writes to the pipe while “wc” only reads from the pipe 7

Section 03 01 Pipe Named pipe, FIFO “mkfifo” generates a named pipe. You can

Section 03 01 Pipe Named pipe, FIFO “mkfifo” generates a named pipe. You can verify it using “ls”. ex $ mkfifo $ ls -l fifo prw-r--r-- 1 usp student 0 Nov 19 03: 22 fifo $ cat < fifo & [1] 9919 $ cat > fifo apple is red Input sentence apple is red Output of cat banana is yellow [1]+ Done cat <fifo $ 8

Section 03 01 Pipe Ex : Chatting using a pipe Generate two pipes. One

Section 03 01 Pipe Ex : Chatting using a pipe Generate two pipes. One pipe for A → B communication, while the other for B → A communication. $ ll total 0 prw-r--r-- 1 usp student 0 Nov 19 03: 47 fifo 1 prw-r--r-- 1 usp student 0 Nov 19 03: 47 fifo 2 $ cat < fifo 2 & [1] 20143 $ cat > fifo 1 hello hi~ nice to meet you~ me too~ → ← 9 $ cat < fifo 1 & [1] 20142 $ cat > fifo 2 hello hi~ nice to meet you~ me too~

Section 04 01 Socket Communication through a network Communication between processes in other systems.

Section 04 01 Socket Communication through a network Communication between processes in other systems. Signal and pipe are limited for the IPC within the same system. Connection oriented and non connection oriented Connection oriented Non connection oriented Connection establishment procedure is required. There is no need to establish a connection. At the end of the IPC, Dis-connect is required. No need to disconnect Protocol guarantee the delivery of the message to the destination. The deliver is not guaranteed. A message may get lost. TCP (transmission control protocol) UDP (user datagram protocol) 10

Section 04 01 Socket Internet address A unique address to designate a computer in

Section 04 01 Socket Internet address A unique address to designate a computer in the Internet. 4 bytes binary number. (IP version 4) Use dotted decimal representation “ 222. 31. 200. 87”. Processes use original binary number. A transform is required. IP (internet protocol) is the protocol that finds internet address. 11

Section 04 01 Socket Port A number to select a server program to communicate.

Section 04 01 Socket Port A number to select a server program to communicate. Has a 2 bytes number. Should be unambiguous. Select a number that is not used in the system. well-known port The port numbers used by wellknown internet services. service port daytime 13 ftp 21 telnet 23 http 80 12

Section 04 01 Socket socket Socket is similar with the file descriptor. It is

Section 04 01 Socket socket Socket is similar with the file descriptor. It is required for a process to do the IPC. The difference between a socket and a file descriptor is There is a file behind a file descriptor while there is a process behind a socket. A process writes to a socket and reads from the socket. Socket contains information such as internet address and port number of the partner process in the communication. 13