check file's status and lock it, how?

check file's status and lock it, how?

Post by xiaoni » Wed, 12 Feb 1997 04:00:00



Hi, there:

I'd like to write a program which checks a file's status.
If no processes update/modify it, I can then lock it and
read the data and load it into the shared memory. So, my
questions are:

. how could I know if there is any other process accessing
  it or not?

. how could I lock it?

. say that I could lock the file. what will happen when
  someone tries to update it using ftp/rcp/copy? Will the
new data be lost?

Appreciate your help!

Lance


 
 
 

check file's status and lock it, how?

Post by » Fri, 14 Feb 1997 04:00:00


Quote:> . how could I know if there is any other process accessing
>   it or not?

You can't. Sorry.

Quote:> . how could I lock it?

There are a couple of ways. I prefer using fcntl. You can lock the entire
file or just portions. There's also lockf, flock, and other variations.

Quote:> . say that I could lock the file. what will happen when
>   someone tries to update it using ftp/rcp/copy? Will the
> new data be lost?

Depends. If everybody accessing the file uses locks, there will be no
collision. But not all systems make locking mandatory, so even if some
processes are using locks, other processes can still do anything they will
to the file at the same time.

--
His hands are cold and heart is hot     |   S M Ryan, Cupertino CA

The shadowed glooms are shapeless dooms.| or risk losing the mail.
He dreads the lessons demon-taught.     |  I don't use no smileys.

 
 
 

check file's status and lock it, how?

Post by Michel Prévos » Fri, 14 Feb 1997 04:00:00



> Hi, there:

> I'd like to write a program which checks a file's status.
> If no processes update/modify it, I can then lock it and
> read the data and load it into the shared memory. So, my
> questions are:

> . how could I know if there is any other process accessing
>   it or not?

> . how could I lock it?

> . say that I could lock the file. what will happen when
>   someone tries to update it using ftp/rcp/copy? Will the
> new data be lost?

> Appreciate your help!

> Lance



I think that you should read about the fcntl(2) and stat(2) functionw in
your man pages.

Michel

 
 
 

1. Couldn't open status file /var/lock/samba/STATUS....LCK

I am attempting to set up a Linux/Windows network and when I try to test if
samba is working with the command "smbstatus " I get the following response:
" Couldn't open status file /var/lock/samba/STATUS....LCK "
What am I doing incorrect???
Steven A. Wimmer

-------------------------------------------------------------
Admit Nothing,
Deny Everything,
Volunteer Accusations.
-------------------------------------------------------------

2. how to use disk beyond cylander 1024

3. How to check Linux's file cahcing status?

4. libxlf90?

5. Modem TX and RX status via Num Lock-Caps Lock-Scroll Lock

6. semget() and semop() - related issue

7. How to check for Num Lock status

8. Enhance Security Question

9. "Can't read lock file /tmp/.X0-lock"

10. modem locked but I can't find the lock file

11. How do I check my child's status?

12. checking the status of a ftp file transfer

13. checking for file/open status