How to check the lock status?

J

Janice

How to obtain the lock status of a file held by other process?
If I read the file that is locked by other process, the read would
return -1.
If the file is locked by other process, how to put the read to sleep for a
second and try again after a period of time?
Thanx
 
K

Keith Thompson

Janice said:
How to obtain the lock status of a file held by other process?
If I read the file that is locked by other process, the read would
return -1.
If the file is locked by other process, how to put the read to sleep for a
second and try again after a period of time?

There's no way to do this in standard C. Try a newsgroup that's
specific to your system (comp.unix.programmer,
comp.os.ms-windows.programmer.win32, or whatever).
 
R

Raymond Martineau

How to obtain the lock status of a file held by other process?

You need to ask the newsgroup of the operating system you are asking about.
It can be any of the following (as stated in the "Welcome to comp.lang.c!"
posting):

:Operating Systems
:
: DOS, BIOS, Memory Models,
: interrupts, screen handling,
: hardware
: MS/Windows: Mice, DLLs, hardware
: MS 32-bit API
: OS/2 Programming
: Macintosh Programming
: General Unix: processes, pipes,
: POSIX, curses, sockets
: news:comp.unix.[vendor] Various Unix vendors
: Linux application programming
If I read the file that is locked by other process, the read would
return -1.

You should refer it to EOF, not -1. While not critical, it does help
provide the context at which a '-1' will appear. In addition, you really
should provide the name of the function you are using to read - for
example, if you are using the fgetc() function or something else.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top