본문 바로가기

Archived(CSE)/시스템 프로그래밍

Chap 11. Connecting to Processes Near and Far Servers and Sockets

Chap 11. Connecting to Processes Near and Far Servers and Sockets


* Unix - one Interface(FILE IO interface) -> disk, device, pipe, socket

* Client -Server Process

client - interface / server - service supply

* example) BC(client) - DC(server)

* BC - DC 

* fdopen(fd, 모드), fopen(filename, 모드), popen(명령어, 모드)  => FILE * 반환

* popen() -> fp 값으로 fprintf fscanf 등 가능


* Socket server, client

* socket Server - socket, bind, listen, accept(fd 반환), read/write(fp), close

* socket client - socket, connect, read/write(socket id), close 




 

0) pipe 두개 열고 fork < 부모 프로세스 - bc, 자식 프로세스 - dc >

1) 부모 프로세스에서 문자열 scan 이때 , pipe 두 개 중 한개는 write(fpout), 한 개는 read(fpin)로 fdopen을 통해 FILE 포인터로 갖기.

2) 부모 프로세스 fpout에다 scan한 문자열 반환 // fflush 비워주기

3) 자식 프로세스에서 한쪽 dup2로 stdin(부모에서 write한 것), 다른 한 쪽 dup2로 stdout(부모에서 read한 것)로 처리

4) 자식 프로세스에서 execlp(명령어, "-", NULL) 실행

5) 부모 프로세스에서 fpin으로부터 fgets해서 문자열 가져오기(dc 출력값)

6) 출력