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 2502 numberwhun 3,509
Recognized Expert Moderator Specialist
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
Recognized Expert Contributor
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
KevinADC 4,059
Recognized Expert Specialist
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
KevinADC 4,059
Recognized Expert Specialist
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?
KevinADC 4,059
Recognized Expert Specialist
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) :
1- plain win32 C++ DLL projects (little over a dozen, refered to as BASE
OBJECTS)
2- ATL/COM/C++ DLLs which use the plain win32 DLLs...
|
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.
I have made sure all the dependancies and the build order is correct but the
actually instance of VS.Net (devenv.exe) is LOCKING THE DAM DLL'S IT IS...
|
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 it,
it throws an exception.
How to solave this problem? So second process can wait until first
process completes its processing on the file.
...
|
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 restart the application before
the locks are released. I tried it first as:
Image i = ... ; // correctly instantiated to some image...
|
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:
I am trying to use the SaveFileDialog class to get a filename, which is
subsequently opened for writing (write access, read sharing, but using...
|
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 C#". Both
have been developed in .NET Framework 2.0.
Recently I have started getting error in Windows application that "xml
file is being locked...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |