[fpc-pascal] Methods for autoupdating fpc programs?

Mark Morgan Lloyd markMLl.fpc-pascal at telemetry.co.uk
Sun Oct 4 18:58:10 CEST 2015


J├╝rgen Hestermann wrote:
> Am 2015-10-04 um 15:41 schrieb Mark Morgan Lloyd:
>> Michael Van Canneyt wrote:
>>> On Sun, 4 Oct 2015, Graeme Geldenhuys wrote:
>>>
>>>> On 2015-10-04 13:16, Mattias Gaertner wrote:
>>>>> Replacing a running program by simply copying can result under 
>>>>> Linux in
>>>>> 'text file busy'.
>>>>
>>>> Then consider me luckily. :) In my 15 years of using Linux and 4 years
>>>> of FreeBSD I have never seen that error.
>>>
>>> I see it nearly every day, when I recompile a fastcgi process that is 
>>> still in use by Apache.
>>>
>>> But I was also surprised to see it. I'm still not sure what the exact 
>>> cause is, because it works sometimes, and sometimes not.
>>
>> It generally happens if the OS (almost any OS) decides that 
>> constrained resources means that a segment can usefully be removed 
>> from memory, and further decides that it's a read-only segment so 
>> rather than writing it to swap it will- if it needs it again- reread 
>> it from the original binary.
>>
> 
> But that makes no sense to me. If the OS is designed to potentially 
> remove running programs (or parts of it) from memory it cannot allow 
> overwriting the file on disk in any case. When it does so, it cannot 

If it hasn't yet removed a read-only segment then it doesn't have to 
hold the binary open. If it wants to remove a read-only segment and 
finds that the binary has already been removed or changed then it can 
write it to swap.

> remove parts from memory because it may not be available on disk 
> anymore. So it must disallow the disk change from the beginning, 
> otherwise it may not be able to remove anything.

If the OS has initially read the entire program into memory then it can 
close the file.

This is why people who periodically reinvent the idea of forcing the OS 
to discard initialisation code aren't being quite as bright as they 
think, since in general there isn't a flag which says "this will never, 
under any circumstances whatsoever, be reexecuted".

This is an enormous can of worms, particularly if the OS (or Apache 
etc.) is inclined to share segments in memory if a program is reexecuted.

-- 
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]



More information about the fpc-pascal mailing list