LinuxFreeBSD

[알림판목록 I] [알림판목록 II] [글목록][이 전][다 음]
[ LinuxFreeBSD ] in KIDS
글 쓴 이(By): hoo (知星苑)
날 짜 (Date): 1998년 4월 23일 목요일 오전 01시 03분 28초
제 목(Title): 이코드에 잘못된게 있습니까?


/* lock-file.c */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>

int
main (int argc, char *argv[])
{
  struct flock lock_info;
  int fd_no;

  fd_no = open ("a.out", O_RDWR);
  if (fd_no == -1)
    {
      perror ("open ()");
      exit (1);
    }

  while (1)
    {
      if (-1 == fcntl (fd_no, F_GETLK, &lock_info))  /* get lock info */
        {
          perror ("fcntl()");
          exit (1);
        }
      printf ("Lock stat of %s : %d \n", lock_info.l_type);
      if (lock_info.l_type != F_UNLCK) sleep (1); /* if file is locked then 
sleep */
      else
        {
          lock_info.l_type = F_RDLCK; /* lock for reading */
          lock_info.l_whence = SEEK_SET;
          lock_info.l_start = 0l;
          lock_info.l_len = 0;
          fcntl (fd_no, F_SETLK, &lock_info);
          break;
        }
    }

  printf (" %s file locked ...\n", argv[0]);
  printf (" I'm going to sleep. \n");
  printf (" Press Ctrl-C to unlock! \n");
  while (1) sleep (5);

  return 0;
}


-----
 현재 디렉토리에 a.out이라는 파일은 있고
 gcc -o lock-file lock-file.c
 이렇게 컴파일도 잘 됩니다. 

 그런데 아래와 같은 메시지를 출력하고 마는 군요.
 fcntl(): Invalid argument

 분명이 문제가 없는것 같은데, 왜 이런 에러가 나는지 잘 모르겠네요.
 누구 아시는 분 없어요? 


  
[알림판목록 I] [알림판목록 II] [글 목록][이 전][다 음]
키 즈 는 열 린 사 람 들 의 모 임 입 니 다.