How to reliably startup/shutdown tclserver /sclclient. ====================================================== Ron Fox Sept 26, 2003 D. Christian Dinca October 3, 2003 I have seen many laborious methods used to start tclserver and an associated sclclient, ensuring that prior instances of sclclient are properly shutdown. This application note describes and annotates a particularly simple, and reliable method to do this. The following are the operational concerns this application note addresses: - Ensuring that sclclient gets started with the proper data source. - Destroying the instance of sclclient that was created when the the tclserver exits. We assume that most users define the environment variable DAQHOST to be the system on which readout is run. the following tclserver tcl script fragment illustrates the preferred approach: set dataurl "tcp://$env(DAQHOST):2602/" set clientpid [exec sclclient $dataurl & ] bind . {if {"%W" == "."} {exec kill $clientpid}} Line 1 constructs the URL of the data source for the scaler client line 2 spawns up the sclclient program for this tcl server with the appropriate URL. The pid of the process is saved in the variable clientpid. line 3 establishes a handler that is invoked when the main top level window is destroyed. The if statement guarantees that the binding fires only when the top level widget is destroyed. This handler kills the scaler client. This works because: - Normal exits of tclserver will destroy the main toplevel which will invoke the handler. This includes exits forced by clicking the [X] window decoration. - Signals sent to tclserver will be inherited by the child processes by default. Therefore even e.g. a Control-C at the controlling terminal will kill off the sclclient. This is preferrable to the approach where the tclserver and sclclient are started off as independent background processess because in that case, logging off will not kill sclclient, and the next user will have it lying in wait to connect to their tclserver.