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.
8 2471
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
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: - 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
Maybe make deleting the file a recursive function and give it so many attempts before finally giving up. - sub delete {
-
my $file = shift;
-
my $n = shift || 1;
-
my $error = shift || 'unknown error';
-
do_some_error("Can't delete $file: $error") if $n > 5;
-
unless (unlink ($file)) {
-
sleep (1); # sleeps for one second before trying again;
-
delete($file,++$n,$!);
-
}
-
}
Of course this is a work-around and may not work at all.
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: - 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
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: - 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
The file may just be open is the reason you can't delete it. Can we see the perl code?
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?
You have not checked anything really, you assume the open/close functions are successful, try this and see if you get any error messages: - open(STATUSLOG,">>"$StatusFile) or die "Can't open $StatusFile: $!";
-
print STATUSLOG "COMPLETED";
-
close(STATUSLOG) or die "Can't close $StatusFile: $!";
Sign in to post your reply or Sign up for a free account.
Similar topics
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
|
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)...
|
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.
...
|
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" )
|
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.
|
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...
|
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...
|
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:
...
|
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...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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,...
| |