[OS] Operating System(3-2): Process
๐ ์ด์์ฒด์ ์ ๊ณต ์์ ์ ๋ฆฌ
IPC - Message Passing
๐Message Passing์ ๋ ๊ฐ์ง ์ฃผ์ ์ฉ๋๋ฅผ ๊ฐ์ง๋ค
- communicate
- synchronize
- ํ๋ก์ธ์ค๊ฐ ์๋ก ์ ๋ณด๋ฅผ ์ฃผ๊ณ ๋ฐ์ ๋, ์ง์ ๊ฐ์ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์ฐ์ง ์๊ณ (๊ณต์ ๋ณ์ ์์ด)
send(message)
์receive(message)
๊ธฐ๋ฅ์ ํตํด ํต์ ํ ์ ์๋ค. message size is fixed or variable
- ๋ ํ๋ก์ธ์ค P์ Q๊ฐ ํต์ ํ๋ ค๋ฉด:
communication link
๋ฅผ ์ค์ ํด์ผ ํ๋ฉฐ, ๊ทธ ํsend
/receive
๋ฅผ ํตํด ๋ฉ์์ง๋ฅผ ์ฃผ๊ณ ๋ฐ์
โ Implementation issues:
- ๋งํฌ ์ค์ ๋ฐฉ๋ฒ?
- ๋งํฌ๋น ํ์ฉ๋๋ ํ๋ก์ธ์ค์ ์?
- ํต์ ์ ํ์ํ ๋งํฌ์ ์?
- ๋งํฌ์ ์ฉ๋?
- ๋ฉ์ธ์ง์ ํฌ๊ธฐ๋ ๊ณ ์ /๊ฐ๋ณ ?
- ๋งํฌ๋ ๋จ๋ฐฉํฅ์ผ๊น ์๋ฐฉํฅ์ผ๊น?
๐**link์ ๊ตฌํ ๋ ๊ฐ์ง ๋ฐฉ์**:
- ๐ฆ Physical
- Shared Memory
- Hardware Bus
- Network
- ๐ง Logical
Direct
vsIndirect
(์ง์ ํต์ vs ๊ฐ์ ํต์ )Synchronous
vsAsynchronous
(๋๊ธฐ vs ๋น๋๊ธฐ)Automatic
vsExplicit
Buffering (์๋ vs ๋ช ์์ ๋ฒํผ๋ง)
Direct Communication
Processes must name each other explicitly
โ ๊ฐ ํ๋ก์ธ์ค๋ ์๋๋ฐฉ์ ์ด๋ฆ์ ๋ช
์์ ์ผ๋ก ์์์ผ ๋ฉ์์ง๋ฅผ ๋ณด๋ผ ์ ์์
send(P, message)
โ P๋ผ๋ ํ๋ก์ธ์ค์๊ฒ ๋ฉ์์ง๋ฅผ ๋ณด๋receive(Q, message)
โ Q๋ผ๋ ํ๋ก์ธ์ค๋ก๋ถํฐ ๋ฉ์์ง๋ฅผ ๋ฐ์
โ Properties of communication link
- Links are established automatically
- A link is associated with exactly one pair of communicating processes
- Between each pair, there exists exactly one link
- Link may be unidirectional, but is usually bi-directional
๋จ์ํ์ง๋ง, ์ ์ฐ์ฑ์ด ๋จ์ด์ง ์ ์์ (์๋๋ฐฉ ์ด๋ฆ์ ๋ฏธ๋ฆฌ ์์์ผ ํจ)
Indirect Communication
๐Indirect Communication: Mailbox
๋ฅผ ์ด์ฉํ ๋ฉ์์ง ์ ๋ฌ
- ๋ฉ์์ง๋ `mailbox`๋ฅผ ํตํด ์ก์์ ๋๋ค (Mach์์๋ mailbox๋ฅผ โportโ๋ผ๊ณ ์นญํจ)
- ๊ฐ
mailbox
๋ ๊ณ ์ ํ ID๋ฅผ ๊ฐ์ง๋ฉฐ, ์ด๋ฅผ ๊ณต์ ํด์ผ๋ง ํ๋ก์ธ์ค ๊ฐ ํต์ ์ด ๊ฐ๋ฅ
โ **Properties of communication link**:
- Link establish only if processes share a common mailbox
- ํ๋์ mailbox๋ ์ฌ๋ฌ ํ๋ก์ธ์ค์ ์ฐ๊ฒฐ ๊ฐ๋ฅ
- ํ๋ก์ธ์ค ์๋ง๋ค ์ฌ๋ฌ ๊ฐ์ ํต์ ๋งํฌ๋ฅผ ๊ฐ์ง ์ ์์
- Link may be unidirectional or bi-directional
- Mailboxes๋ ๋ค์๊ณผ ๊ฐ์ operations์ ์ง์
- ์๋ก์ด mailbox ์์ฑ
- ๋ฉ์์ง ์ก์์
- mailbox ์ ๊ฑฐ
- ์์ ํจ์(primitive)๊ฐ ์กด์ฌ:
send(A, message)
โ mailbox A์ ๋ฉ์์ง ๋ณด๋receive(A, message)
โ mailbox A๋ก๋ถํฐ ๋ฉ์์ง ๋ฐ์
โ Mailbox ๊ณต์ ๋ฌธ์ & ํด๊ฒฐ ๋ฐฉ๋ฒ
P1, P2, P3๊ฐ ๊ฐ์ mailbox A๋ฅผ ๊ณต์
P1์ด ๋ฉ์์ง๋ฅผ ๋ณด๋
๊ทธ๋ฐ๋ฐ P2์ P3๊ฐ ๋์์ ๋ฐ์ผ๋ ค๊ณ ํ๋ฉดโฆ?โ ๋๊ฐ ๋ฉ์์ง๋ฅผ ๋ฐ๊ฒ ๋ ๊น?
โ Solutions:
- mailbox๋ ์ต๋ 2๊ฐ์ ํ๋ก์ธ์ค๋ง ์ฐ๊ฒฐ ๊ฐ๋ฅํ๋๋ก ์ ํ
- ํ ๋ฒ์ ํ๋์ ํ๋ก์ธ์ค๋ง receive ๊ฐ๋ฅ
- ์์คํ ์ด receiver ์ ํ, Sender์๊ฒ ๋๊ฐ ๋ฐ์๋์ง ์๋ ค์ค
๐ง Synchronization
- Message passing ๋ฐฉ์์
blocking
๊ณผnon-blocking
์ด ์๋ค. - Blocking
- Blocking = synchronous
Blocking send
: ๋ฉ์์ง๋ฅผ ๋ณด๋ธ ํ๋ก์ธ์ค๋ ์๋๊ฐ ๋ฐ์ ๋๊น์ง ๊ธฐ๋ค๋ฆผ โ Queue ์ฌ์ฉ ์ non-blocking ํจ๊ณผ ๊ฐ๋ฅBlocking receive
: ๋ฉ์์ง๋ฅผ ๋ฐ์ ํ๋ก์ธ์ค๋ ๋ฉ์์ง๊ฐ ๋์ฐฉํ ๋๊น์ง ๊ธฐ๋ค๋ฆผ- ๋ ๋ค ๊ธฐ๋ค๋ฆฌ๊ธฐ ๋๋ฌธ์ ์๊ฐ ๋๊ธฐํ๊ฐ ์ ๋ง์ โ ์์ ์ ์ด์ง๋ง ๋๋ฆด ์ ์์
- Non-blocking
- Non-blocking = Asynchronous
Non-blocking send
: ๋ฉ์์ง ๋ณด๋ธ ํ ๊ธฐ๋ค๋ฆฌ์ง ์๊ณ ๋ฐ๋ก ๋ค์ ์ผ ์ํ โ ๋ฉ์์ง ์์ค ๋ฐฉ์ง๋ฅผ ์ํด Queue ํ์Non-blocking receive
: ์์ ์๋ ๋ค์ ์ค ํ๋๋ฅผ ์ฆ์ ๋ฐ์- ์ ํจํ ๋ฉ์์ง
- ๋น ๋ฉ์์ง (null)
- ๋ค์ํ ์กฐํฉ ๊ฐ๋ฅ
Blocking + Blocking
: rendezvous(๋ฐ๋ฐ๋ทฐ)(:์๋ก ๋ฑ ๋ง๋ ๋๊น์ง๋ง ๋๊ธฐ)Non-blocking + Non-blocking
: ์๋ก ์ ๊ฒฝ ์ ์ โ ๋ฉ์์ง ์์ค ๊ฐ๋ฅ์ฑ ํผ
๐Blocking send/receive
๋ฅผ ์ฌ์ฉํ producer/consumer ๋ฌธ์ โ rendezvous
ํ์
Producer-message Passing:
1
2
3
4
5
6
message next_produced;
while (true){
/* produce an item in next_produced */
send(next_produced); // blocking send
}
Consumer-message Passing:
1
2
3
4
5
6
message next_consumed;
while (true){
receive(next_consumed); // blocking receive
/* consume the item in next_consumed */
}
- ์ ์ฒด ํ๋ฆ ๊ทธ๋ฆผ
1 2 3 4
๐ข Producer ๐ข Consumer produce item wait for item โ โ send(item) โโโโโ[rendezvous]โโโ receive(item)
๋ ๋ค blocking ์ํ์ด๋ฏ๋ก, ๋ฑ ๋ง๋์ ๋ฐ์ดํฐ๋ฅผ ๊ตํํจ
์ผ์ข ์ โ์ฝ์๋ ๋ง๋จโ์ด๋ฏ๋ก ๋ฐ์ดํฐ ์์ค ์์
Buffering
๐Buffering: Blocking send/receive์ ์ฑ๋ฅ์ ํฅ์์ํด
โ Implemetns in one of three ways:
- Zero capacity:
- ํ๊ฐ ์์
- ๋ฉ์์ง๋ ๋ฐ๋์ ์ฆ์ receiver์๊ฒ ์ ๋ฌ๋์ด์ผ ํจ
- Receiver๊ฐ ์ค๋น๋์ง ์์ผ๋ฉด Sender๋ ๊ธฐ๋ค๋ ค์ผ ํจ =
rendezvous
๋ฐฉ์(์์ ๋๊ธฐ)
- Bounded capacity:
- ํ์ ์ต๋ n๊ฐ์ ๋ฉ์์ง๊น์ง ์ ์ฅ ๊ฐ๋ฅ
- ํ๊ฐ ๊ฐ๋ ์ฐผ์ ๊ฒฝ์ฐ, Sender๋ ๊ธฐ๋ค๋ ค์ผ ํจ
- Unbounded capacity:
- ์ด๋ก ์ ์ผ๋ก ๋ฌดํํ ๋ง์ ๋ฉ์์ง๋ฅผ ์ ์ฅ ๊ฐ๋ฅ
- Sender๋ ์ ๋ ๊ธฐ๋ค๋ฆฌ์ง ์์ โ ์์ ํ ๋น๋๊ธฐ
- ํ๊ฐ ๋์น ๊ฑฑ์ ์ด ์์ง๋ง ๋ฉ๋ชจ๋ฆฌ ๊ณผ๋ค ์ฌ์ฉ ๊ฐ๋ฅ์ฑ ์์
Examples of IPC Systems - POSIX
๐POSIX Shared Memory
- ํ๋ก์ธ์ค๋
shm_open()
์ ํตํด ๊ณต์ ๋ฉ๋ชจ๋ฆฌ ๊ฐ์ฒด๋ฅผ ์์ฑํ๊ฑฐ๋ ์ด ์ ์์ shm_fd()
=shm_open(name, O_CREAT | O_RDWR, 0666);
ftruncate()
๋ฅผ ์ด์ฉํด ๋ฉ๋ชจ๋ฆฌ ๊ฐ์ฒด์ ํฌ๊ธฐ๋ฅผ ์ง์ ftruncate(shm_fd, 4096)
(4096์ size)mmap()
์ ํตํด ์ด ๊ณต์ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์ค์ ์ฃผ์ ๊ณต๊ฐ(file pointer)์ ๋งคํ- ์ดํ ์ด
mmap()
๋ pointer๋ฅผ ํตํด ๋ฉ๋ชจ๋ฆฌ์ ์ ๊ทผ(read/write) ๊ฐ๋ฅํจ.
1
2
3
4
5
6
ํ๋ก์ธ์ค A (Producer) ํ๋ก์ธ์ค B (Consumer)
---------------------- ----------------------
1. shm_open() ์์ฑ 1. shm_open() ์ด๊ธฐ
2. ftruncate() ํฌ๊ธฐ ์ค์ 2. mmap()์ผ๋ก ๋งคํ
3. mmap()์ผ๋ก ์ฃผ์ ๋งคํ 3. ํฌ์ธํฐ๋ก ๋ฐ์ดํฐ ์ฝ๊ธฐ
4. ํฌ์ธํฐ๋ก ๋ฐ์ดํฐ ์ฐ๊ธฐ 4. shm_unlink()๋ก ์ ๊ฑฐ
- IPC POSIX Producer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/shm.h>
#include <sys/stat.h>
int main()
{
/* the size (in bytes) of shared memory object */
const int SIZE = 4096;
// name of the shared memory object
const char *name = "OS";
// strings written to shared memory
const char *message_0 = "Hello";
const char *message_1 = "World";
// shared memory file descriptor
int shm_fd;
// pointer to shared memory object
void *ptr;
// create the shared memory object
shm_fd = shm_open(name, O_CREAT | O_RDWR, 0666);
// configure the size of the shared memory object
ftruncate(shm_fd, SIZE);
// memory map the shared memory object
ptr = mmap(0, SIZE, PROT_WRITE, MAP_SHARED, shm_fd, 0);
// write to the shared memory object
sprintf(ptr, "%s", message_0);
ptr += strlen(message_0);
sprintf(ptr, "%s", message_1);
ptr += strlen(message_1);
return 0;
}
shm_open
์ผ๋ก ๊ณต์ ๋ฉ๋ชจ๋ฆฌ ๊ฐ์ฒด ์์ฑ
ftruncate
๋ก ํฌ๊ธฐ ์ง์ (4096 ๋ฐ์ดํธ)
mmap
์ผ๋ก ๊ณต์ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์์ ์ ๋ฉ๋ชจ๋ฆฌ ๊ณต๊ฐ์ ์ฐ๊ฒฐ
์ดํsprintf
๋ก ๋ฉ์์ง๋ฅผ ๊ณต์ ๋ฉ๋ชจ๋ฆฌ์ ์ฐ๊ธฐ
Copy-on-write
๋ ๋ณต์ฌ๋ฅผ ๋๊ธฐํ๋ค๊ฐ write ํ ๋ ๋ณต์ฌํด์ฃผ๋ ์ต์
- IPC POSIX Consumer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/shm.h>
#include <sys/stat.h>
int main()
{
/* the size (in bytes) of shared memory object */
const int SIZE = 4096;
// name of the shared memory object
const char *name = "OS";
// shared memory file descriptor
int shm_fd;
// pointer to shared memory object
void *ptr;
// open the shared memory object
shm_fd = shm_open(name, O_RDONLY, 0666);
// memory map the shared memory object
ptr = mmap(0, SIZE, PROT_READ, MAP_SHARED, shm_fd, 0);
printf("%s", (char *)ptr);
// remove the shared memory object
shm_unlink(name);
return 0;
}
shm_open
์ผ๋ก ๊ธฐ์กด ๊ณต์ ๋ฉ๋ชจ๋ฆฌ ์ด๊ธฐ
mmap
์ผ๋ก ์ฝ๊ธฐ ์ ์ฉ ๋งคํ
๊ณต์ ๋ฉ๋ชจ๋ฆฌ์์ ๋ฌธ์์ด์ ์ฝ์ด์ ์ถ๋ ฅ
์ฌ์ฉ ํshm_unlink()
๋ก ๊ณต์ ๋ฉ๋ชจ๋ฆฌ ์ ๊ฑฐ
shm_unlink()
๋ โ๊ณต์ ๋ฉ๋ชจ๋ฆฌ ๊ฐ์ฒด ์์ฒด ์ ๊ฑฐโ ์ญํ
Examples of IPC Systems โ Windows
๐ALPC(Advanced Local Procedure Call)๋ ๋์ผํ ์์คํ ๋ด ํ๋ก์ธ์ค๋ค๋ผ๋ฆฌ ํต์ ํ๊ธฐ ์ํ `message-passing`๊ธฐ๋ฐ **IPC ๋ฐฉ์**์ด๋ค
ALPC
๋ RPC(์๊ฒฉ ํ๋ก์์ ํธ์ถ)์ ์ ์ฌํ์ง๋ง, ๋ก์ปฌ์์๋ง ์๋ํจport
(like mailbox)๋ฅผ ์ฌ์ฉํ์ฌ ํต์ ์ฑ๋์ ์ค์ ํ๊ณ ์ ์ง ๊ด๋ฆฌ
โ ์๋ ์๋ฆฌ
- Client๊ฐ ์ฐ๊ฒฐ ์์ฒญ ์์
- ํด๋ผ์ด์ธํธ๋
subsystem
์connection port
์ ๋ํ handle์ ์ฐ๋ค - ์ด connection port๋ ๋ชจ๋ ํ๋ก์ธ์ค์๊ฒ ๋ณด์
- ํด๋ผ์ด์ธํธ๋
- Client โ ์ฐ๊ฒฐ ์์ฒญ(connection request) ์ ์ก
- Server๊ฐ ํต์ ์ค๋น
- ์๋ฒ๋ twoprivate communication ports๋ฅผ ์์ฑํฉ๋๋ค.
- ์ด ์ค ํ๋์ ํฌํธ๋ฅผ ํด๋ผ์ด์ธํธ์๊ฒ ๋ค์ ์ ๋ฌ
- ์๋ฐฉํฅ ํต์ ์์
- ํด๋ผ์ด์ธํธ์ ์๋ฒ๋ ์ ๋ฌ๋
port handle
์ ํตํด ๋ฉ์์ง๋ฅผ ์ฃผ๊ณ ๋ฐ๊ฑฐ๋ callback์ ์ฌ์ฉ ๊ฐ๋ฅ
- ํด๋ผ์ด์ธํธ์ ์๋ฒ๋ ์ ๋ฌ๋
PIP
๐ Pipes: ํ์ดํ๋ ๋ ๊ฐ์ ํ๋ก์ธ์ค ๊ฐ์ ๋ฐ์ดํฐ๋ฅผ ์ฃผ๊ณ ๋ฐ๊ธฐ ์ํ ํต๋ก(conduit) ์ญํ
- ํ๋ก์ธ์ค A โ ํ๋ก์ธ์ค B ๋ก ๋ฐ์ดํฐ๋ฅผ ์ ์กํ ์ ์๋๋ก ๋ง๋ค์ด์ง ํต์ ๊ตฌ์กฐ
- ํ์ผ์ฒ๋ผ ์ฐ๊ณ ์ฝ์ ์ ์์
โ ํต์ฌ ์ด์๋ค:
- ๋ฐ์ดํฐ๋ฅผ ํ ๋ฐฉํฅ์ผ๋ก๋ง ๋ณด๋ผ ์ ์๋์ง (๋จ๋ฐฉํฅ/unidirectional), ์์ชฝ ๋ชจ๋ ๊ฐ๋ฅ (์๋ฐฉํฅ/bidirectional)์ธ์ง
Half-duplex
์ธ์ง,Full-duplex
์ธ์ง? (ex - Simplex: ํค๋ณด๋, Half-duplex: ๋ฌด์ ๊ธฐ, Full-duplex: ์ ํ๊ธฐ)- ํต์ ํ๋ ค๋ฉด ๋ถ๋ชจ-์์ ๊ด๊ณ๊ฐ ํ์ํ๊ฐ?
- ๋คํธ์ํฌ๋ฅผ ํตํด ์ฌ์ฉ ๊ฐ๋ฅํ๊ฐ?
โ **๋ ๊ฐ์ง ํ์ดํ ์ข ๋ฅ**:
- Ordinary Pipe
- ์ ํ๋ ๊ด๊ณ: ๋ถ๋ชจ-์์ ๊ด๊ณ์์๋ง ์ฌ์ฉ ๊ฐ๋ฅ
- ์ธ๋ถ ์ ๊ทผ ๋ถ๊ฐ: ํ์ดํ๋ฅผ ๋ง๋ ํ๋ก์ธ์ค ์ธ๋ถ์์ ์ ๊ทผ ๋ถ๊ฐ๋ฅ
- ์์: ๋ถ๋ชจ๊ฐ ์์ ๋ง๋ค๊ณ โ ์์์๊ฒ ํ์ดํ๋ก ๋ช ๋ น ์ ๋ฌ
- Named Pipe
- ๋ ๋ฆฝ์ ์ธ ํต์ ๊ฐ๋ฅ: ๋ถ๋ชจ-์์ ๊ด๊ณ ํ์ ์์
- ํ์ผ ์์คํ ์์ ์ด๋ฆ์ ๊ฐ์ง โ ๋ค๋ฅธ ํ๋ก์ธ์ค์ ์ฝ๊ฒ ๊ณต์ ๊ฐ๋ฅ
- ์์:
ls | less
(์ ๋์ค์์ ๋ง์ด ์ฌ์ฉ)
Ordinary Pipe
๐Ordinary Pipe: ํ ํ๋ก์ธ์ค๊ฐ ์ฐ๊ธฐ(write) ํ๊ณ , ๋ค๋ฅธ ํ๋ก์ธ์ค๊ฐ ์ฝ๊ธฐ(read) ํ๋ ๋จ๋ฐฉํฅ(unidirectional) ํต์ ์ฉ ํ์ดํ
์์ฑํ ํ๋ก์ธ์ค(๋ถ๋ชจ)๋ ์์ ๋ง pipe๋ฅผ ๋ณผ ์ ์์
ํ์ง๋ง ์์ ํ๋ก์ธ์ค๋ ์์๋ฐ์ ์ด๋ฆฐ ํ์ผ๋ก pipe ์ ๊ทผ ๊ฐ๋ฅ
โ **์๋ ๋ฐฉ์**:
- Producer โ ๋ฐ์ดํฐ๋ฅผ ์์ฑ(write)
- Consumer โ ๋ฐ์ดํฐ๋ฅผ ์ฝ์(read)
- ํ ๋ฐฉํฅ(unidirectional) ์ผ๋ก๋ง ํต์ ๊ฐ๋ฅ
- Windows์์๋ anonymous pipe ๋ผ๊ณ ํ๋ค
- ํ์ดํ๋ ์ด์์ฒด์ ์
์ฅ์์๋ ํน์ํ ํ์ผ๋ก ์ทจ๊ธ๋๋ฏ๋ก
read()
/write()
๋ฅผ ๊ทธ๋๋ก ์ฌ์ฉํด ํต์ ์ด ๊ฐ๋ฅ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// ํ์ดํ ์์ฑ
if (pipe(fd) == -1) {
fprintf(stderr, "Pipe failed");
return 1;
}
// ์์ ํ๋ก์ธ์ค ์์ฑ
pid = fork(); //๋ถ๋ชจ ํ๋ก์ธ์ค๋ pid > 0,์์ ํ๋ก์ธ์ค๋ pid == 0
if(pid<0){
fprintf(stderr, "Fork Failed");
return 1;
}
if(pid > 0){// parent process
close(fd[READ_END]);// ์ฝ๊ธฐ์ฉ ๋ซ์ (์ ์)
write(fd[WRITE_END], write_msg, strlen(write_msg) + 1);
close(fd[WRITE_END]); // ์ฐ๊ธฐ ๋๋๊ณ ๋ซ์
}
else{//child process
close(fd[WRITE_END]); // ์ฐ๊ธฐ์ฉ ๋ซ์
read(fd[READ_END], read_msg, BUFFER_SIZE); // ๋ฉ์ธ์ง ์์
printf("read %s", read_msg);
close(fd[READ_END]); // ์ฝ๊ธฐ ๋๋๊ณ ๋ซ์
}
Named Pipe
๐Named Pipe:์ด๋ฆ ์๋ ํ์ดํ. ํ์ผ ์์คํ ์์ ์กด์ฌ
- ๐ ์๋ฐฉํฅ ํต์ (Bidirectional) ๊ฐ๋ฅ
- ๋ถ๋ชจ-์์ ๊ด๊ณ ๋ถํ์: ๋ ๋ฆฝ๋ ํ๋ก์ธ์ค ๊ฐ์๋ ์ฌ์ฉ ๊ฐ๋ฅ
- Ordinary Pipes๋ณด๋ค ๋ ๊ฐ๋ ฅํ๊ณ ์ ์ฐํจ โ
UNIX
&Windows
๋ชจ๋์์ ์ฌ์ฉ ๊ฐ๋ฅ
1
int mkfifo(const char *pathname, mode_t mode);
pathname
: FIFO์ ์ด๋ฆmode
: ์ ๊ทผ ๊ถํ ์ค์ (์: 0666) ์ดํopen()
,read()
,write()
,close()
๋ฑ ์ผ๋ฐ ํ์ผ์ฒ๋ผ ๋ค๋ฃธ
์์ด
ls | less
๋ช ๋ น์ด๋ฅผ ์ฒ๋ฆฌํ๋ ๊ตฌ์กฐ โls
๊ฐ ์ถ๋ ฅ์ pipe์ ์ฐ๊ณless
๊ฐ ๊ทธ๊ฑธ ๋ฐ์ ์ถ๋ ฅํจ.
pipe(fd)
ํธ์ถ๋ก ํ์ดํ ์์ฑfork()
๋ก ์ฒซ ๋ฒ์งธ ์์ ์์ฑ โless
close(fd[1])
: ์ฐ๊ธฐ ์ข ๋ฃdup2(fd[0], 0)
: ํ์ดํ ์ ๋ ฅ์ ํ์ค ์ ๋ ฅ์ผ๋ก ์ฐ๊ฒฐexec()
:less
์คํ- ๋ค์
fork()
โ ๋ ๋ฒ์งธ ์์ ์์ฑ โls
close(fd[0])
: ์ฝ๊ธฐ ์ข ๋ฃdup2(fd[1], 1)
: ํ์ดํ ์ถ๋ ฅ์ ํ์ค ์ถ๋ ฅ์ผ๋ก ์ฐ๊ฒฐexec()
:ls
์คํ
Sokcet
๐Sokcet: ํต์ ์ ์ถ๋ฐ์ /๋์ฐฉ์ ์ญํ ์ ํ๋ ์ํํธ์จ์ด ๊ตฌ์กฐ
- IP ์ฃผ์ + ํฌํธ ๋ฒํธ๋ฅผ ํฉ์ณ์ ์์ผ์ ๊ตฌ๋ถํจ
- ์: 161.25.19.8:1625 โ IP ์ฃผ์: 161.25.19.8, ํฌํธ: 1625
- ํต์ ์ ํญ์ pair๋ก ์ด๋ฃจ์ด์ง (์: ํด๋ผ์ด์ธํธ โ ์๋ฒ)
- 1024๋ฒ ์ดํ ํฌํธ๋ ์์คํ ์์ ์์ฝ๋ ํฌํธ๋ค (HTTP: 80, HTTPS: 443 ๋ฑ)
127.0.0.1
(loopback): ์๊ธฐ ์์ ์๊ฒ ๋ณด๋ด๋ IP ์ฃผ์ (์: ์๋ฒ/ํด๋ผ์ด์ธํธ๋ฅผ ํ ์ปดํจํฐ์์ ํ ์คํธ)
Remote Producer calls(RPC)
๐ ๋คํธ์ํฌ๋ฅผ ํตํด ๋ค๋ฅธ ์ปดํจํฐ์ Producer(ํจ์)๋ฅผ ๋ก์ปฌ์ฒ๋ผ ํธ์ถ
- ์ฌ์ฉ์๋ ๋ง์น ์์ ์ ์ปดํจํฐ์์ ํจ์๋ฅผ ์คํํ๋ ๊ฒ์ฒ๋ผ ์ฌ์ฉํ์ง๋ง, ์ค์ ๋ก๋ ๋ค๋ฅธ ์ปดํจํฐ์์ ์คํ
__์ฃผ์ ์์:__
- Stubs:
- Client Stub: ํด๋ผ์ด์ธํธ ์ชฝ์์ ์๋ฒ ํจ์๋ฅผ ๋์ ํธ์ถํ๋ ์ฝ๋
- Server Stub: ์๋ฒ ์ชฝ์์ ํด๋ผ์ด์ธํธ์ ์์ฒญ์ ๋ฐ์ ์ง์ง ํจ์๋ฅผ ํธ์ถ
- Marshalling / Unmarshalling::
- ๋ฐ์ดํฐ๋ฅผ ์ ์กํ๊ธฐ ์ํด ํฌ๋งท์ ๋ณํํ๊ณ (Marshalling), ๋ฐ๋์ชฝ์์ ๋ค์ ํด์ํ๋ ๊ฒ(Unmarshalling)
Windows์์๋ ์ด ๊ณผ์ ์ ์ํ ์ฝ๋ ์คํ์ ์ ์ํ๋ Microsoft Interface Definition Language(MIDL)๋ฅผ ์ฌ์ฉ
- XDL(External Data Representation): ์๋ก ๋ค๋ฅธ ์์คํ
๊ฐ ๋ฐ์ดํฐ ํํ ๋ฐฉ์์ ํต์ผ
- Big-endian and little-endian * ๋ฉ์ธ์ง ์ ๋ฌ ๋ฐฉ์(remote communication์ local๋ณด๋ค ์ค๋ฅ๊ฐ ๋ง๊ธฐ ๋๋ฌธ)
exactly once
: ๋ฉ์์ง๊ฐ ํ ๋ฒ๋ง ์ฒ๋ฆฌ๋๋๋ก ๋ณด์ฅat most once
: ์ค๋ณต ๋ฉ์์ง ๋ฐฉ์ง, ๋ฌด์ ๊ฐ๋ฅ์ฑ ์กด์ฌ- ํด๋ผ์ด์ธํธ์ ์๋ฒ ์ฌ์ด์๋ ๋คํธ์ํฌ ์ง์ฐ์ด๋ ์์ค์ด ๋ฐ์ํ ์ ์๊ธฐ ๋๋ฌธ์ ์ ํํ ํ ๋ฒ ์ฒ๋ฆฌ(exactly once)๋ฅผ ๊ตฌํํ๋ ๊ฒ์ด ์ค์
- ์ด๋ฅผ ์ํด ACK(์๋ต ํ์ธ)๋ฅผ ํตํด ์์ฒญ ์ฒ๋ฆฌ ์๋ฃ๋ฅผ ์๋ ค์ค
- rendezvous(matchmaker):
- ํด๋ผ์ด์ธํธ๊ฐ ์๋ฒ๋ฅผ ์ฐพ๋๋ก ๋์์ฃผ๋ OS ์๋น์ค