On 30/08/24 18:09, Anon Loli wrote: > On Thu, Aug 29, 2024 at 07:03:11PM -0400, Nick Holland wrote: >> On 8/29/24 16:11, Anon Loli wrote: >>> Okay, I have an vague idea about what happens, let me 1st add this to the >>> bug >>> report: >>> >>> So I launched a half a dozen tmux windows and they had archivemedia script >>> running and while I started all the windows, I went on to edit the script >>> and >>> add a few lines, >> so...you were editing a running script? I do believe that falls under the >> category, "undefined behavior". Yeah, I kinda expect things to go bad >> when you do that. >> >> You are probably assuming the file is loaded in RAM at start and stays there >> until done. That's not how it works, I am pretty sure I've tried it and not >> got away with it before, too. >> >> Nick. > Of course I assumed that the file would be loaded in RAM lol why wouldn't I?
Because it's a waste of both memory and time to load an entire file in memory before executing it, especially since the nature of the shell. Also, IIRC the Thompson shell relied on this to implement conditionals. > It's the only thing that makes sense to me, but then again I don't know how > executing scripts works exactly *shrug*. > > I would like to know why that is, perhaps this is already answered in e-mails > I'm yet to read, but my OS will not have this unlogical and unreliable and > actually I'm assuming that this is also UNDOCUMENTED undefined behavior, and > as > > such, ksh.1 manual page is at fault here, this is a bugs. unfortunately, this is how unix actually works. Even if ksh used memory-mapped I/O, it could still concurred edits to the files. Heck, in some cases using memory-mapped I/O could lead to worst issues (imagine a concurrent process truncating the file while you're reading it, and say hello to SIGBUS.) Note that this also depends on how the editor you're using writes the files back to the disk. Some editors will just rewrite the file in-place, which means that other processes can see these concurred edits, while others will use a tempfile + rename scheme. No one is strictly better than the other. (if you think this is only related to weird and/or "ancient" stuff well, I was VERY surprised while trying the vis editor (vise on openbsd), and seeing the content on the monitor getting corrupted after I did a "echo > file" :-)