[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: locking of files

Hi Vinu,

  It dows work in Linux and i have tried some sample programs too.
 Did you lseek to the right position before locking the record / file ?
 Also u can try flock where u can be certain about the type of lock u can
obtain ( Exclusive lock )
#include <stdio.h>
#include <fcntl.h>

void main()

   int fd;
   int a;
   fd = open("abcd",1);

   a = lockf(fd,F_TEST,0);

   a = lockf(fd,F_LOCK,0L);

   a = lockf(fd,F_ULOCK,0);

run this program with ./a.out & ./a.out & ./a.out & ....
and u will see that the first process gets the lock and the other process
gets permission denied ....

- Mahesh

"lock.c" 22L, 278C

----- Original Message -----
From: Linux List <linux-prog@xxxxxxxxx>
To: <linux-india-programmers@xxxxxxxxxxxxxxxxxxxxx>
Sent: Wednesday, July 19, 2000 11:53 AM
Subject: [LIP] locking of files

> hi all,
>     Tried locking of files in linux.
> I used the function lockf(fd,F_LOCK,0L);
> I am not able to lock.Has someone tried it out.Is
> there a error in the program or some compatibility(of
> the lockf system call) problems with linux.
> vinu
> -----------------------------------------------------------------------
> The LIP mailing list archives are available at:
> http://lists.linux-india.org/cgi-bin/wilma/linux-india-programmers