1 / 7

고급 프로세스간 통신 message queue semaphore shared memory fcntl 을 사용한 레코드 록킹 - 읽기록 - 쓰기록

고급 프로세스간 통신 message queue semaphore shared memory fcntl 을 사용한 레코드 록킹 - 읽기록 - 쓰기록 int fcntl(int filedes, int cmd, struct flock *ldata) . cmd – F_GETLK, F_SETLK, F_SETLKW . Ldata – l_type (F_RDLCK, F_WRLCK, F_UNLCK), l_whence, off_t l_start, off_t l_len, pid_t l_pid). 고급 프로세스간 통신

jerry
Télécharger la présentation

고급 프로세스간 통신 message queue semaphore shared memory fcntl 을 사용한 레코드 록킹 - 읽기록 - 쓰기록

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 고급 프로세스간 통신 • message queue • semaphore • shared memory • fcntl 을 사용한 레코드 록킹 • -읽기록 • -쓰기록 • int fcntl(int filedes, int cmd, struct flock *ldata) • . cmd – F_GETLK, F_SETLK, F_SETLKW • . Ldata – l_type (F_RDLCK, F_WRLCK, F_UNLCK), l_whence, • off_t l_start, off_t l_len, pid_t l_pid)

  2. 고급 프로세스간 통신 • fcntl 을 사용한 레코드 록킹 • -예제 – p251 (test1.c) • -록 정보는 fork 호출에 의해 계승되지 않는다 • fcntl 호출의 파일포인터를 변경시키지 않는다 • 한 프로세스에 속한 모든 록은 그 프로세스가 죽을 때 자동적으로 제거

  3. deadlock (test2.c – p256) • 실습 • 파일 testfile의 0에서 4바이트까지 lock • fork를 호출하여 자식 프로세스 생성 • 자식 프로세스는 5에서 9바이트까지와 0 에서 4바이트까지를 lock하려고 시도한다. 두번째의 lock시도는 부모프로세스가 lock한 영역이므로 자식프로세스는 대기 • 부모프로세스는 sleep를 호출하여 10초간 휴면, 자식이 두 번의 lock을 수행할 수 있도록 한다. • 부모가 깨어나면 5 에서 9 바이트까지 lock을 시도한다

  4. 고급 IPC 설비 • IPC 설비 키 • key_t ftok(const char *path, int id) • msgget의 결과 IPC 설비 식별자 return • - mqid = msgget((key_t)0100, 0644 | IPC_CREAT | IPC_EXCL); • ipc_perm • uid_t cuid; • gid_t cgid; • uid_t uid; • gid_t gid; • mode_t umode;

  5. 메시지 전달 • int msgget(key_t key, int permflags); • IPC_CREAT • IPC_EXCL • mqid = msgget((key_t)0100, 0644 | IPC_CREAT | IPC_EXCL); • int msgsnd(int mqid, const void *message, size_t size, int flags); • int msgrcv(int mqid, void *message, size_t size, long msg_type, int flags); • struct mymsg { • long mtype; • char mtext[SOMEVALUE}; • }

  6. 메시지 전달 • IPC_NOWAIT, MSG_NOERROR • msg_type • - msg_type > 0 • 그 값을 갖는 첫 메시지를 읽음 • - msg_type = 0 • 큐의 제일 첫 번째 메시지를 읽음 • - msg_type < 0 • 메시지의 mtype 값이 msg_type의 절대값보다 작거나 같은 것 • 중에서 최소값을 갖는 첫 번째 메시지를 읽음 • (예제) etest.c, stest.c, q.h

  7. 실습 • fork와 message queue를 사용한 통신 프로그램 • 자식이 표준 입력한 내용을 mtype=1로 부모에게 전달 • 더 이상의 내용이 없을 때 자식은 mtype=2로 전달 • 부모는 mtype=1이면 받은 내용을 출력하며, mtype=2이면 exit • ipcs & ipcrm –q key

More Related