lock 설정 에러가..ㅠㅠ

익명 사용자의 이미지

락을 설정을 해서 락이 지금 작동하는지 알아볼려고 하는데요 락설정이
에러가 났다고 나오네요 근데 어디가 설정이 잘못되는지 아무리 찾아봐
도 안보이네요 소스는 동일한 파일을 열어서 한 넘이 락을 하고 다른 놈
이 또 락을 하면 나중에 하는 사람이 멈추도록 하는건데 errno에 값이
안들어오네요 .ㅠㅠ 고수님들 도움좀..
#include
#include
#include
#include
#include
#include
#include

#define FALSE 0
#define SEC_SET 1000000
#define tzp 0

int main(void)
{
char print_data;
FILE *fd;
pid_t pid;

// file open
#include
#include
#include
#include
#include
#include
#include

#define FALSE 0
#define SEC_SET 1000000
#define tzp 0

int main(void)
{
char print_data;
FILE *fd;
pid_t pid;

// file open
fd = fopen("test", "r");

switch(pid = fork())
{
case 0
lock_test(fd, F_RDLCK, 0, 10);
printf("Child\n");
break;
default
wait_time (tzp,SEC_SET);
lock_test(fd, F_RDLCK, 1, 10);
printf("pae~!!\n");
break;
}

printf("unlocking\n");
lock_test(fd, F_UNLCK, 0, 10);

to_time();

exit(0);
}

int lock_test(int file, int type, int start, int len)
{
struct flock data_lock;

data_lock.l_type = type;
data_lock.l_whence = SEEK_SET;
data_lock.l_start = start;
data_lock.l_len = len;

if ( fcntl(file, F_SETLK, &data_lock) < FALSE){
if (errno == EACCES || errno == EAGAIN || errno ==
EBADF){
printf("Error test\n");
return(0);
}
else
{
printf("Error2\n");
return(1);

}}
}

int wait_time(int sec, int usec)
{
struct timeval the_time;
the_time.tv_sec = sec;
the_time.tv_usec = usec;
select(0, (fd_set*) 0, (fd_set*) 0, (fd_set*) 0, &the_time);

return(0);
}

int to_time()
{
// the_time
struct timeval Hab_time;
struct tm *tm_ptr;

gettimeofday(&Hab_time, tzp);
tm_ptr = gmtime(&Hab_time.tv_sec);
printf("hour %d년 %d월 %d일 %d%
d\n", tm_ptr->tm_year +
1900, tm_ptr->tm_mon +1,
tm_ptr->tm_mday, tm_ptr->tm_hour-
3, tm_ptr->tm_min);

return(0);
}

익명 사용자의 이미지

1일째 wrote..
락을 설정을 해서 락이 지금 작동하는지 알아볼려고 하는데요 락설정이
에러가 났다고 나오네요 근데 어디가 설정이 잘못되는지 아무리 찾아봐
도 안보이네요 소스는 동일한 파일을 열어서 한 넘이 락을 하고 다른 놈
이 또 락을 하면 나중에 하는 사람이 멈추도록 하는건데 errno에 값이
안들어오네요 .ㅠㅠ 고수님들 도움좀..
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
#include <time.h>
#include <sys/time.h>
#include <sys/types.h>

#define FALSE 0
#define SEC_SET 1000000
#define tzp 0

int main(void)
{
char print_data;
FILE *fd;
pid_t pid;

// file open
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
#include <time.h>
#include <sys/time.h>
#include <sys/types.h>

#define FALSE 0
#define SEC_SET 1000000
#define tzp 0

int main(void)
{
char print_data;
FILE *fd; // 아까 말씀드린건데여 이것을 int fd;로 하시구여..

pid_t pid;

// file open
fd = fopen("test", "r"); // 이것을
// fd = open(filename, O_RDONLY);
// 하셔야 fcntl()가 제대로 작동안합니다.
// 분명 에러는 아규먼트 인자 타입이 틀렸다고 에러가 날겁니
다.

switch(pid = fork())
{
case 0
lock_test(fd, F_RDLCK, 0, 10);
printf("Child\n");
break;
default
wait_time (tzp,SEC_SET);
lock_test(fd, F_RDLCK, 1, 10);
printf("pae~!!\n");
break;
}


printf("unlocking\n");
lock_test(fd, F_UNLCK, 0, 10);

to_time();

exit(0);
}




int lock_test(int file, int type, int start, int len)
{
struct flock data_lock;

data_lock.l_type = type;
data_lock.l_whence = SEEK_SET;
data_lock.l_start = start;
data_lock.l_len = len;

if ( fcntl(file, F_SETLK, &data_lock) < FALSE){
if (errno == EACCES || errno == EAGAIN || errno ==
EBADF){
printf("Error test\n");
return(0);
}
else
{
printf("Error2\n");
return(1);

}}
}


int wait_time(int sec, int usec)
{
struct timeval the_time;
the_time.tv_sec = sec;
the_time.tv_usec = usec;
select(0, (fd_set*) 0, (fd_set*) 0, (fd_set*) 0, &the_time);

return(0);
}


int to_time()
{
// the_time
struct timeval Hab_time;
struct tm *tm_ptr;

gettimeofday(&Hab_time, tzp);
tm_ptr = gmtime(&Hab_time.tv_sec);
printf("hour %d년 %d월 %d일 %d%
d\n", tm_ptr- >tm_year +
1900, tm_ptr->tm_mon +1,
tm_ptr->tm_mday, tm_ptr->tm_hour-
3, tm_ptr->tm_min);

return(0);
}

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.