Version 1 of Make a script withdraw itself to the background

Updated 2005-08-16 15:42:36

sbron 16 Aug 2005: In the Tcl chatroom Donal Fellows provided a method for a script to restart itself in the background. It goes something like this:

 if {[lindex $argv 0] ne "-dorealprocessing"} {
     exec [info nameofexecutable] [info script] \
         -dorealprocessing [lindex $argv 0] >/dev/null &
     exit
 }
 # The real code goes here ...

This code simply restarts the shell that's executing the script in the background with one additional parameter and then exits. This should of course only be done when the additional parameter is not present to prevent an endless sequence of new processes.

The code will probably need to be adapted slightly if used in combination with a starpack.