one of those bad weekends.. file locking by processes
Results 1 to 2 of 2

Thread: one of those bad weekends.. file locking by processes

  1. #1
    Join Date
    Feb 2003

    one of those bad weekends.. file locking by processes

    Hello Ppl,
    Ever get one of those days when though u've been programming for over an year, you still occasionally end up doing something utterly dumb.. but come out of it learning something new.. ok, here's my rant:

    I have two variants of a genetic algorithms program I've been working on, the makefile is pretty much the same. (Using RHLinux 8.0)

    For file 1_GA.c
    gcc -o ga 1_GA.c -lm
    For file 2_GA.c
    gcc -o ga 2_GA.c -lm

    I always started both these programs at the same time, needed to study their outputs. And the results for 2_GA.c always were totally off-mark.. my program design was correct, no logical errors, no coding faults but o/p just wasn't rite. For those who know GA's, there wasn't any convergence for 2_GA.c

    So, here I was, spending over 2 days with ddd, going over 5000 lines of code... till about half an hour ago. My problem - I was compiling both programs (the compilation took around 3 minutes) into the same executable - ga!! I change the name, (or run them one by one).. EUREKA!! runs fine!

    So, anyway, my question: (about time I asked it too) - what happens in the above sorta situation, which process gets to lock the file and write? which starves? do both write??
    Also is there any way I can check what files are being read/written by a process?

    Thanx for reading this far, hope someone can answer.. laterz

  2. #2
    Senior Member
    Join Date
    Jan 2002
    Hmm, I'm not sure I entirely understand your question.

    Under these *nix like operating systems, there is not normally any mandatory file locking. That's to say, an application is not prevented from writing to a file by it being locked. This sounds useless but it works well for mailboxes, databases etc.

    If you are running an exe, the file *may* be unwriteable if it's being executed (gives "text file busy"). However, the compiler may delete the old exe when compiling and put the new one in its place.

    If the old exe is deleted and a new one put in its place, it can continue executing despite not being there any more. Erm, well something like that.

    Unix allows files to continue to exist after they've been deleted. If you compile a new program over the same exe, it will not be the same file or something like that. I dunno how to explain it.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts