Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close a file but other process stil cannot use it

Status
Not open for further replies.
Mar 13, 2002
34
MY
After closing a file I call another process that would access that file :
open(MYFILE, ">>test");
do something with the file.
close(MYFILE);
system("myprog >>log") && warn "Error : ";

Myprog would access the file test.
However myprog complaints that the file is currently being used by another process which should be my perl script process.
When I close the file is the file still open and cannot be used by other process ? How do I go about solving this ?
 
Forget to mention that :
The script was ran in a windows 2000 Professional edition where I use the MKS kornshell (part of MKS toolkit for system administrators) to execute the script.

When I use the same script in a unix environment, I have no problem.
 
I've noticed when running scripts in a Windows environment that it takes a second or two before the file actually closes and is able to be used by other processes. Normally, what I do to get around this problem is add the line

Code:
sleep 2;

This avoids the problems that can occur where the request to close the file is sent and my program moves on, but Windows hasn't released the file for other processes to use yet. Sounds hokey, I know, but it's the only thing I can think of that would cause this.

- Rieekan
 
More like 20-40 seconds, worst case I've seen.

Try deleting a program after stopping it, or watching the temp files from VIM dissappear after stopping VIM.
 
You've discovered one of the big problem with Win32 systems. The original idea for Windows was a GUI, that sat on top of a disk handling system. The two were written completely independently, and although MS have tried to improve the interface there are still several flaws, one of which is the file locking process.

As others have mention you need to wait a while to allow the unlocking process to happen. If your system call is to a C program or another perl script, you could use flock() to help out. It still won't be perfect, but it might help.

Barbie. Leader of Birmingham Perl Mongers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top