isbn: 9780130810816 대학교 vol 1을 읽었고 너무 오래된 시스템이라 잘 실행안됬음을 기억했다. 가벼운 마음으로 IPC를 알아보려 찾았는데, 600페이지 책 한 권을 읽고 있다. 책도 나온지 너무 오래되어 웬만하면 하나 사려고 했는데, 종이책으로만 있다!! 인터넷에서 잘 찾았다. 아래 그림은 개요장에 있는데 이 그림으로 길고 지루한 길을 쉽게 갈 수 있다. 예상한 바와 같이 파일로 정보를 공유함은…… unix network programming, vol 2 계속 읽기


semaphore p223 ~ p238
name semaphore는 /dev/shm에 저장된다. 이름을 엄한 /tmp/xxx 이런 식으로 만들면 세마포어를 만들 수 없다. segment error로 죽는다. 책에서는 /tmp/로 넣어도 잘 동작해서 확인하는데 오래 걸렸다. 디버그 하다 중간에 멈추면 /dev/shm에 sem*로 파일을 지울 수 없어 다음 실행에 세마포어를 받을 수 없다. 처음 시작 전 자기 이름으로 된 세마포어 있으면 지워야 한다. thread를 돌리면 미친 race…… semaphore p223 ~ p238 계속 읽기
sync, mutex. unix network programming p161
다시 thread로 돌아왔다. #include <stdlib.h> #include <stdio.h> #include <string.h> #include <pthread.h> #define MAXNITEMS 1000000 #define MAXNTHREADS 100 #define MIN(X,Y) ((X)<(Y) ? (X) : (Y)) //gcc -lpthread 옵션으로 컴파일. int nitems; /* read-only by producer and consumer */ //shared를 초기화 하는데, //맨 처음에 mutext가 있음. //나머지는 0으로 초기화됨.. struct { pthread_mutex_t mutex; int buff[MAXNITEMS]; int nput;…… sync, mutex. unix network programming p161 계속 읽기
fifo 예제. unix network programming 55p
pipe는 이름을 없어 parent, child process만 통신이 가능하다. 이를 보안한게 named pipe인데, fifo라고도 한다. 책은 다른 유닉스 버전으로 작성하여, linux에 맞게 수정했다. 결론적으로 pipe와 비슷하고 더 쉽다. #include <stdlib.h> #include <stdio.h> #include <errno.h> #include <unistd.h> #include <sys/types.h> #include <fcntl.h> #include <sys/wait.h> #include <string.h> #include <sys/stat.h> #include <unistd.h> #define FIFO1 “/tmp/fifo.1” #define FIFO2 “/tmp/fifo.2” #define MAXLINE…… fifo 예제. unix network programming 55p 계속 읽기