473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

File is getting Locked. Pls help

Hi
This is my first post to this forum.

I am struck up with a problem.

We have a perl script which deals with creation/deletion of files. This perl script is trigerred through a java webservice. But at times the files are getting locked by a process. We are not able to delete the files. the error message is " Cannot accoss the file <file name> because it is used by another process"

So pls help to resolve.

Note: When the restart the tomcat server which hosts the webservice, it is deleting the file. In my code I am closing the file handles correctly.
Jan 17 '08 #1
8 2471
numberwhun
3,509 Expert Mod 2GB
Hi
This is my first post to this forum.

I am struck up with a problem.

We have a perl script which deals with creation/deletion of files. This perl script is trigerred through a java webservice. But at times the files are getting locked by a process. We are not able to delete the files. the error message is " Cannot accoss the file <file name> because it is used by another process"

So pls help to resolve.

Note: When the restart the tomcat server which hosts the webservice, it is deleting the file. In my code I am closing the file handles correctly.
Are you able to determine what is using the files you are trying to delete? Stopping the access to the files will help.

Regards,

Jeff
Jan 17 '08 #2
prn
254 Expert 100+
Are you able to determine what is using the files you are trying to delete? Stopping the access to the files will help.
On a *ix system, at least, you can probably determine what is locking the file with lsof. I'd suggest logging that information before you attempt to delete the file. Something like:
Expand|Select|Wrap|Line Numbers
  1. system ("lsof $filename >>$log");
ought to work for you.

If your system does not have lsof on it (most systems seem not to have it in the default installation) you may need to install it. If you are not the sysadmin, you'll need to get the sysadmin to do it as it requires privileges. However, lsof is something that every sysadmin ought to have in his/her bag of tricks. It's great, it's portable, and it is indispensible for situations like this. I've used it on Solaris and Linux, it is also available for just about any other flavor of unix or unix-like system.

Best Regards,
Paul
Jan 17 '08 #3
KevinADC
4,059 Expert 2GB
Maybe make deleting the file a recursive function and give it so many attempts before finally giving up.

Expand|Select|Wrap|Line Numbers
  1. sub delete {
  2.    my $file = shift;
  3.    my $n = shift || 1;
  4.    my $error = shift  || 'unknown error'; 
  5.    do_some_error("Can't delete $file: $error") if $n > 5;
  6.    unless (unlink ($file)) {
  7.       sleep (1); # sleeps for one second before trying again;
  8.       delete($file,++$n,$!);
  9.    }
  10. }

Of course this is a work-around and may not work at all.
Jan 17 '08 #4
Hi
Thanks for the reply. I will try it out and get back to you.

On a *ix system, at least, you can probably determine what is locking the file with lsof. I'd suggest logging that information before you attempt to delete the file. Something like:
Expand|Select|Wrap|Line Numbers
  1. system ("lsof $filename >>$log");
ought to work for you.

If your system does not have lsof on it (most systems seem not to have it in the default installation) you may need to install it. If you are not the sysadmin, you'll need to get the sysadmin to do it as it requires privileges. However, lsof is something that every sysadmin ought to have in his/her bag of tricks. It's great, it's portable, and it is indispensible for situations like this. I've used it on Solaris and Linux, it is also available for just about any other flavor of unix or unix-like system.

Best Regards,
Paul
Jan 18 '08 #5
Hi Paul

I am using windows 2000. Do you suggest me any utility in Windows to find out which process has locked my file. I am facing the File locking problem in a production server. So it will be better if there are things already available in the OS (Not need of downloading any extra thing)

Thanks for your help.

Regards
Finny

On a *ix system, at least, you can probably determine what is locking the file with lsof. I'd suggest logging that information before you attempt to delete the file. Something like:
Expand|Select|Wrap|Line Numbers
  1. system ("lsof $filename >>$log");
ought to work for you.

If your system does not have lsof on it (most systems seem not to have it in the default installation) you may need to install it. If you are not the sysadmin, you'll need to get the sysadmin to do it as it requires privileges. However, lsof is something that every sysadmin ought to have in his/her bag of tricks. It's great, it's portable, and it is indispensible for situations like this. I've used it on Solaris and Linux, it is also available for just about any other flavor of unix or unix-like system.

Best Regards,
Paul
Jan 28 '08 #6
KevinADC
4,059 Expert 2GB
The file may just be open is the reason you can't delete it. Can we see the perl code?
Jan 28 '08 #7
Hi
Thanks for the reply.

I am very sure that the file handlers are closed. I am closing the handlers at all cases. I have checked that multiple times.
(e.g)
open(STATUSLOG,">>"$StatusFile);
print(STATUSLOG "COMPLETED");
close(STATUSLOG);
Java webservice is invoking the perl scripts. It also does some operations with that file. I doubt whether java webservice is locking the file.

Inorder to confirm that, i need to find which is locking the file. That java code is not my code. Before pointing out my hand to others code, i am trying to have some valid point for me.

Thats why i have to find the process which has locked the file.

Regards
Finny
The file may just be open is the reason you can't delete it. Can we see the perl code?
Jan 28 '08 #8
KevinADC
4,059 Expert 2GB
You have not checked anything really, you assume the open/close functions are successful, try this and see if you get any error messages:

Expand|Select|Wrap|Line Numbers
  1. open(STATUSLOG,">>"$StatusFile) or die "Can't open $StatusFile: $!";
  2. print STATUSLOG "COMPLETED";
  3. close(STATUSLOG) or die "Can't close $StatusFile: $!";
Jan 28 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Pekka Niiranen | last post by:
Hi, I have used the following example from win32 extensions: -----SCRIPT STARTS---- import win32file import win32con import win32security import pywintypes
14
by: Sin | last post by:
I've tried everything and I've come to the conclusion that I'm screwed. If anyone can help, I would be eternaly greatful. I have a solution which has 47 projects.. This is includes (very roughly)...
4
by: Earth Worm Jim | last post by:
I am using VS.Net 2003 on Windows 2003 Server (standard edition) and I am getting "The process cannot access the file because it is being used by another process" on DLL's in a VS.Net solution. ...
4
by: hkappleorange | last post by:
I ued this code to connect to a mdb file A = New OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=C:\Inetpub\wwwroot\ASPX\Authors.mdb" )
10
by: Atley | last post by:
I am trying to make sure that an MDB is not in use and then delete it. If it is in use, I want to automatically disconnect all the users and then delete the file. Any suggestions are welcome.
1
by: ABCL | last post by:
Hi All, I am working on the situation where 2 different Process/Application(.net) tries to open file at the same time....Or one process is updating the file and another process tries to access...
6
by: JezB | last post by:
I have an Image object (i) which I want to write to a file. This does work but when I later try to do something with this file I get errors, because I think the file is still 'locked'. I have to...
17
by: Peter Duniho | last post by:
I searched using Google, on the web and in the newsgroups, and found nothing on this topic. Hopefully that means I just don't understand what I'm supposed to be doing here. :) The problem: ...
0
by: JM | last post by:
I am working on an application which uses xml file as a database. The application has 2 interfaces which accesses this xml file. "Windows application written in C#" and "Windows Service written in...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.