473,586 Members | 2,702 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

File is getting Locked. Pls help

6 New Member
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 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
Jan 17 '08 #2
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:
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 Recognized Expert Specialist
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
mailtofinny
6 New Member
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
mailtofinny
6 New Member
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 Recognized Expert Specialist
The file may just be open is the reason you can't delete it. Can we see the perl code?
Jan 28 '08 #7
mailtofinny
6 New Member
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 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:

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
7308
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
1691
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...
4
13235
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...
4
2759
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
2711
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
19887
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. ...
6
7610
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...
17
8013
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...
0
1481
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...
0
7839
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...
0
8200
Oralloy
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. ...
0
8215
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 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...
0
6610
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
isladogs
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...
0
3836
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...
0
3864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
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
1
1448
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.