[ CnUnix ] in KIDS 글 쓴 이(By): HellCat ((void*)0) 날 짜 (Date): 1994년04월20일(수) 01시28분48초 KST 제 목(Title): RE: lock lockf, flock and fcntl() check this ex. out. #include <sys/types.h> #include <fcntl.h> pid_t lock_test (int fd, int type, int offset, int whence, int len) { struct flock lock; lock.l_type = type; /* F_RDLCK or F_WRLCK */ lock.l_start = offset; /* byte offset, relative to l_whence */ lock.l_whence = whence; /* SEEK_SET, SEEK_CUR, SEEK_END */ lock.l_len = len; /* # bytes (0 means to EOF) */ if (fcntl(fd, F_GETLK, &lock) < 0) { perror("fcntl"); return (-1); } if (lock.l_type == F_UNLCK) return (0); return (lock.l_pid); } Also, there's no atomic since all sys. calls are interruptable via SIGNAL (except some SYS 5.4.3 has atomic I/O - pread/pwrite) You will probably have to do something like while (fcntl (fd, F_SETLK, &lock) == -1 && errno == EINTR); Or 만약 SYS 5.4 이면 sigaction () 을 사용해서 sa_flags |= SA_RESTART 를 해줌으로서 시그날 인터럽트로중 단 되었을때 시스템 콜 이 중단 된 부분 부터 다시시작 하게끔 해줄수 있습니다. 단 이 SA_RESTART 는 non-POSIX 이고 SVR4 와 4.3+BSD 에만 있을 꺼에요. 근데 이 sigaction 가지고 시그날 액션을 바꿔줄때 SIGALRM 은 조심 해야해요. --- if (t_snddis(KIDS[i].fd, (struct t_call *)NULL) == -1) { t_error("날 죽여라!!"); longjmp ((jmp_buf) HELL, -1); } |