bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Edit vs delete a running script. Why difference?


From: Pierre Gaston
Subject: Re: Edit vs delete a running script. Why difference?
Date: Wed, 18 Jan 2012 09:19:04 +0200

On Wed, Jan 18, 2012 at 6:19 AM, Teika Kazura <address@hidden> wrote:
>
> Hi. When you edit a running bash script, it's affected, so you
> shouldn't do that [1][2]. However, I heard[3] that if you delete the
> script itself from the filesystem, the original is remembered by bash,
> and it continues to run as-is (as-was?). It seems correct as far as I
> tried several times.
>
> What's the, or are there any rationale for this difference? If the
> entire script is read at invocation, then why should / does
> modification affect? Is it a bug?
>

It's due to the way unix works, if you look at the documentation of
unlink, for instance in the posix man page:

"When the file's link count becomes 0 and no process has the file
open, the space occupied by the file shall be freed and the file shall
no longer be accessible. If one or more processes have the file open
when the last link is removed, the link shall be removed before
unlink() returns, but the removal of the file contents shall be
postponed until all references to the file are closed."

You'll notice that your are not really deleting a file, you are
decrementing a counter by one. So what you do when you delete the file
is that you remove one link, since bash has it open to execute the
script there is still a reference to the old script and bash continues
normally.

If you edit the file bash is reading, then everything can happen, you
might edit a portion of the file that bash has read but not yet
executed for instance (since io is buffered).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]