Re: BASH

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

 



On Sat, Dec 04, 2004 at 09:50:21AM -0600, Bill Gradwohl wrote:

> Two questions:
> 
> 1) When a BASH script is executed, the file that represents the script 
> must be read by the interpreter. Assuming the script is a long running 
> script, is it safe to modify the script while its executing? The real 
> question boils down to is the entire script read into memory or not 
> before execution starts, or is it read as needed from disk. I ask 
> because I'd like to test a script, and while its running and I see 
> errors, I'd like to modify the script without disturbing the executing 
> version.
> 
> 2) There seems to be no way to "goto" in BASH. If one has a lengthy 
> script that fails half way down, the only thing to do appears to be to 
> wrap the top half in an if that won't execute so as to skip that top 
> half and get to where the script should again restart. Is there a better 
> way to do this?

This is an interesting topic on which much work has been done.  In the
general case it is not possible to modify code of any type on the fly
safely.   Since the answer to the 'general case' is NO you have
to code exceptional functionality into your script and process
to get things to work.

As for safety of editing files. Depending on the the way your editor
works it may or may not work for you or the same as it does for me.
i.e. In linux a file is opened by name and the file descriptor is
attached to the inode.  If that file is then deleted and another of
the same name replaces it the existing script or program will be ok as
long as it keeps the old inode/ descriptor open.  If the inode of the
file remains unchanged there are risks as the shell seeks to the
next code line.  Different scripting languages also work differently 
in how changes to the source are handled.

There is no 'goto' but there are signal handlers.  ;-)

A signal handler could trap a signal, tidy up then start the new
script with a hint that lets the new script pickup where you expect
(and then the old script exits).  State can be passed in the
environment, a file, or command line.

You can automate this with a Makefile or script that copies the new to
the old and then uses 'killall' or 'kill' to send a trap-able signal
like SIGUSR1 to your old script where the signal is caught and then
the right thing happen.

Event handlers (signal handlers) and this restart stuff is HARD to get
correct both in hardware and in software.  If you design for it
it is possible.


-- 
	T o m  M i t c h e l l 
	spam unwanted email.
	SPAM, good eats, and a trademark of  Hormel Foods.


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux