Index: tolsh/tolsh.vfs/lib/app-tolsh/tolsh.tcl
===================================================================
--- tolsh/tolsh.vfs/lib/app-tolsh/tolsh.tcl	(revision 10a207c91db2f93090f2c1bbf8595cdc6391d16d)
+++ tolsh/tolsh.vfs/lib/app-tolsh/tolsh.tcl	(revision a168f52b60243d0c4c4cbf84a4036c8fb5c2689e)
@@ -166,8 +166,15 @@
         set options(runmode) "slave"
       } elseif {$opt eq "shared"} {
+        # the next argument is the port number
+        set options(shared,port) [lindex $cmdline [expr {$i+1}]]
+        incr i
         if {$options(runmode) ne "" && $options(runmode) ne "shared"} {
           puts "Replacing previous run mode '$options(runmode)' with 'shared'"
         }
         set options(runmode) "shared"
+      }  elseif {$opt eq "shport"} {
+        # the next argument is the port number
+        set options(shared,port) [lindex $cmdline [expr {$i+1}]]
+        incr i
       } else {
         append delayed_msg "\nignoring unknown option: '$item'"
@@ -444,5 +451,5 @@
   } elseif {$options(runmode) eq "shared"} {
     puts "runmode=shared"
-    run_as_shared    
+    run_as_shared $tolcomm_dir
   
   } elseif {$options(runmode) eq "slave"} {
@@ -456,6 +463,7 @@
   package require tolserver
 
-  clone
+  set shared_port [ clone ]
   tolserver::start -port $options(server,port) \
+    -shport $shared_port \
     -logfile [file join $tolcomm_dir "tolserver.log"] \
     -compile $options(compile)
@@ -463,4 +471,19 @@
 }   
 
+proc ::tolsh::find_shared_port { port } {
+  puts "::tolsh::find_shared_port $port"
+  set i 0
+  while { $i < 100 } {
+    if { [ catch { socket localhost $port } fd ] } {
+      puts "find_shared_port OK = $port"
+      return $port
+    }
+    incr port
+    incr i
+  }
+  puts "find_shared_port FAIL!"
+  return 0
+}
+
 proc ::tolsh::clone {} {
   variable options
@@ -471,21 +494,28 @@
     lappend tolsh $::argv0
   }
-  eval exec $tolsh -shared &
+  set shared_port [ find_shared_port 20458 ]
+  if { !$shared_port } {
+    puts "::tolsh::clone: could not find a valid port for shared data"
+    exit
+  }
+  eval exec $tolsh -shared $shared_port &
   after 5000            ;# wait for data sharing are created by 'shared'
   puts "exec slave"
-  eval exec $tolsh -slave $options(server,port) &
-}
-
-proc ::tolsh::run_as_shared {} {
+  eval exec $tolsh -slave $options(server,port) -shport $shared_port &
+  return $shared_port
+}
+
+proc ::tolsh::run_as_shared { tolcomm_dir } {
   package require tolshared
-
-  tolshared::start
+  variable options
+
+  tolshared::start $options(shared,port) $tolcomm_dir
 }   
 
-proc ::tolsh::run_as_slave {tolcomm_dir} {
+proc ::tolsh::run_as_slave { tolcomm_dir } {
   variable options
   package require tolslave
 
-  tolslave::start -port $options(server,port) \
+  tolslave::start -port $options(server,port) -shport $options(shared,port) \
     -logfile [file join $tolcomm_dir "tolslave.log"]
   vwait __forever__
Index: tolsh/tolsh.vfs/lib/tolcomm/tolserver.tcl
===================================================================
--- tolsh/tolsh.vfs/lib/tolcomm/tolserver.tcl	(revision 10a207c91db2f93090f2c1bbf8595cdc6391d16d)
+++ tolsh/tolsh.vfs/lib/tolcomm/tolserver.tcl	(revision a168f52b60243d0c4c4cbf84a4036c8fb5c2689e)
@@ -452,4 +452,5 @@
   array set options {
     -port 6669
+    -shport 20458
     -logfile ""
     -compile ""
@@ -467,5 +468,5 @@
   }
   
-  server_attach_data
+  server_attach_data $options(-shport)
 
   log "debug" "shared_tasks(init)=$options(-compile)"
@@ -474,5 +475,5 @@
 }
 
-proc ::tolserver::server_attach_data {} {
+proc ::tolserver::server_attach_data { shared_port } {
   package require tequila
   global shared_tasks
@@ -480,5 +481,5 @@
   global shared_finish
 
-  tequila::open localhost 20458
+  tequila::open localhost $shared_port
   tequila::attach shared_tasks
   tequila::attach shared_state
Index: tolsh/tolsh.vfs/lib/tolcomm/tolshared.tcl
===================================================================
--- tolsh/tolsh.vfs/lib/tolcomm/tolshared.tcl	(revision 10a207c91db2f93090f2c1bbf8595cdc6391d16d)
+++ tolsh/tolsh.vfs/lib/tolcomm/tolshared.tcl	(revision a168f52b60243d0c4c4cbf84a4036c8fb5c2689e)
@@ -22,5 +22,5 @@
 #
 ###############################################################################
-proc ::tolshared::start {} {
+proc ::tolshared::start { port datadir } {
   global tqs_info
   package require Mk4tcl
@@ -28,7 +28,8 @@
 
   puts "::tolshared::start"
-  mk::file open tqs tequilas.dat -nocommit
+  # OJO: este archivo hay abrirlo en algun directorio controlado
+  mk::file open tqs [ file join $datadir tequilas.${port}.dat ] -nocommit
   set tqs_info(verbose) 0     ;# default logging is off
   TqsTimer ""                 ;# default commit timer is 30 seconds
-  tqsRun 20458                ;# default port is 20458
+  tqsRun $port                ;# default port is 20458
 }
