Anyway to stop programs from locking files?

By Karmashock
Jan 7, 2007
Topic Status:
Not open for further replies.
  1. I have several files that are often read/written to by different programs on a regular basis. As a result it isn't uncommon for some of the files to be locked.


    Is there anyway to allow many different programs to write to a given file at once?


    I really don't care how complex the solution is... It just needs to happen.
  2. jobeard

    jobeard TS Ambassador Posts: 13,351   +301

    Not without rewritting the program. Access to files is performed with a call
    to OPEN() and it takes the file filename and a mode. The ability to allow multiple
    writers requires a mode change and an extra call around each write.

    The other solution is a special process that controls the open/write operations
    and all other programs send data to it via an IPC call.
  3. ravisunny2

    ravisunny2 TS Ambassador Posts: 2,057   +8

    If the file(s) remains locked for too long, someone has done a lousy job.

    As JOBEARD says, the software needs to be modified. Should be easy enough.
  4. jobeard

    jobeard TS Ambassador Posts: 13,351   +301

    it is common for output files to be held open until the task ends -- thus the
    long times. There are huge performance issues for open/write(append)/close on every write
    unless the volume of data is trivial and infrequent.

    only if (1) you have the source and (2) you know how :)
  5. Karmashock

    Karmashock Newcomer, in training Topic Starter Posts: 237

    Screwed on both points... oh well... I guess I can do it a different way. Thanks anyway. :)
  6. jobeard

    jobeard TS Ambassador Posts: 13,351   +301

    let's move back to the top -- What are you trying to do? What program outputs
    are you attempting to merge into one file?
  7. ravisunny2

    ravisunny2 TS Ambassador Posts: 2,057   +8

    Are you trying to access a file not meant for you ?

    If it's not meant for you, you can expect it to be locked at the most unfortunate of times.

    But if the file is meant for multiple access, it shouldn't be locked too long.

    Depends on the application.

    Also you can find a file locked if someone decides to take a cofee break in the midst of a simple entry !
  8. ravisunny2

    ravisunny2 TS Ambassador Posts: 2,057   +8

    Don't give up so easily

    Okay. This is like shooting an arrow in the dark.

    Are you trying to access the file through an application software ?

    What kind of a file is it ?

    If it’s a data file (any kind), you might be able to save yourself a lot of time (at least get something useful done while you’re waiting for the file to get unlocked).

    Write an infinite loop that tries to access the file in question. When access is allowed, pass on the control to your favorite slogan/song (God save the Queen, or whatever (be sure to allow loud beeps, tones, songs …)). Then, again depending on the access rights, lock it yourself, or make a copy, for a leisurely look.

    For heaven’s sake, don’t mess with a file that is not meant for you !

    This way you don’t need to mess with the original source code, and the code you need to write (or get a buddy to write) is nearly elementary
  9. tweakboy

    tweakboy TechSpot Maniac Posts: 518

    Not really,,,,,,,, you can with third party software ,,
  10. jobeard

    jobeard TS Ambassador Posts: 13,351   +301

    what are specifically referring to? Allegations without a citation are not very helpful :(

    For outputs to stdout or stderr, one can use redirection/append mode but direct
    calls to write on a hd or socket handle are not intercepted with trival code.

    Let's get off this thread -- the user has long given up anyway.
  11. tomrice32

    tomrice32 Newcomer, in training Posts: 50

    I don't know if this is what you're looking for but having a quick skim of this topic I thought that this may help:
    http://ccollomb.free.fr/unlocker/

    You can right click a file and choose Unlocker, and it will unlock that file from any processes which are using it. This will then allow you to do what you want with it. More info & screenshots of what I mean on that website.

    That may also be the 'third party software' that tweakboy is referring to I don't know.

    Edit:
    Re-reading your first post again I'm not sure this will actually do what you want, but I'll leave it out there anyway incase it does help. :) Not sure which files you're trying to use or why you would want to be writing to them from two places at once.
     
  12. Karmashock

    Karmashock Newcomer, in training Topic Starter Posts: 237

    it's an old dos version of dBase... it's extremely old... I think my solution will be to upgrade to a newer version... something which we've been afraid to do because we don't know if the new version will work the same way. We've programmed this database continuously for over ten years and the thought of redoing any of it would be death.


    basically lots of users access a single database all the time and 95 percent of the time it works fine but every once in a while part of the db is locked by another user that is editing it... you can't even read it...
  13. tomrice32

    tomrice32 Newcomer, in training Posts: 50

    Apologies if it sounds obvious but you could make a backup of the database, then if the newer version of dBase doesn't work how you want it to then restore the old one.

    Don't know anything about dBase so that's all I can suggest. Hopefully someone else will understand better.
  14. Karmashock

    Karmashock Newcomer, in training Topic Starter Posts: 237

    that's a great program... I use it sometimes for other things. But it's not what I need.


    Ideally I'd need to have some way to have programs think they were locking files when in fact they weren't... but then for all I know that could lead to horrible file corruption. So I think it's hopeless.
  15. jobeard

    jobeard TS Ambassador Posts: 13,351   +301

    you should be thankful! this kind of locking is done to protect the file from multiple writes that would trash the file. If not done like this, your data would be corrupted.
    this is a trival GUI to reset the Read Only attribute and avoid the multiple clicks
    down to the property sheet. this is not the same thing as the file locking due to
    an active program
  16. Karmashock

    Karmashock Newcomer, in training Topic Starter Posts: 237

    All your help is appreciated... looks like we have no choice but to take the plung and upgrade.
Topic Status:
Not open for further replies.


Add New Comment

TechSpot Members
Login or sign up for free,
it takes about 30 seconds.
You may also...


Get complete access to the TechSpot community. Join thousands of technology enthusiasts that contribute and share knowledge in our forum. Get a private inbox, upload your own photo gallery and more.