Multithreading TCL:使用exec启动2个新的TCL shell时共享的作用域
假设我有一个名为upgrade的过程,用于升级机器/设备。我想同时升级两台机器。在一个名为main的过程中,我使用exec启动2个tcl shell,最终调用升级过程。问题是,在我使用exec启动2个tcl Shell之前,我必须连接到一个流量生成器,该流量生成器只允许一个连接实例连接到它。如果您已经连接到它,您可以连接到它。如何使新启动的Shell upgrade proc意识到连接已经存在,并且不需要连接到它?新创建的shell似乎不共享主进程的空间和范围 请注意,如果我不串联使用exec和callupgrade,则两个升级调用都知道连接和升级工作 也许我在TCL做多重处理时出错了 感谢您的帮助exec将不会继承任何打开的文件描述符 一个可能的解决方案是:让子流程连接到父流程。父进程将接受连接并将所有数据直接传递给流量生成器,并将任何响应发送回相应的子进程 编辑: 另一个解决方案是重写升级过程以同时处理多个升级。这可能比使用exec更容易 主要问题是,您将需要某种方法来确定从traffic manager接收的数据用于哪个进程或升级连接。无论您使用上述方法,还是重写升级过程以使其一次处理多个升级,这都是正确的 如果您无法路由来自traffic manager的传入数据,那么您想做的事情将很困难 这段代码过于简化了。没有错误检查,也不处理套接字的关闭 套接字上的任何操作都应该包含在try{}块中,因为套接字错误可以在任何时间点发生 此外,如果发送二进制数据,连接需要正确设置其编码Multithreading TCL:使用exec启动2个新的TCL shell时共享的作用域,multithreading,multiprocessing,tcl,exec,Multithreading,Multiprocessing,Tcl,Exec,假设我有一个名为upgrade的过程,用于升级机器/设备。我想同时升级两台机器。在一个名为main的过程中,我使用exec启动2个tcl shell,最终调用升级过程。问题是,在我使用exec启动2个tcl Shell之前,我必须连接到一个流量生成器,该流量生成器只允许一个连接实例连接到它。如果您已经连接到它,您可以连接到它。如何使新启动的Shell upgrade proc意识到连接已经存在,并且不需要连接到它?新创建的shell似乎不共享主进程的空间和范围 请注意,如果我不串联使用exec和
# First, the server (the main process) must create the
# server socket and associate it with a connection handler.
# A read handler is set up to handle the incoming data.
proc readHandler {sock} {
global tmsock
if {[gets $sock data] >= 0} {
puts $tmsock $data
}
}
proc connectHandler {sock addr port} {
global socks
# save the socket the connection came in on.
# the array index should not be the port, but rather some
# data which can be used to route incoming messages from the
# traffic manager.
set socks($port) $sock
fconfigure $sock -buffering line -blocking false
fileevent $sock readable [list ::readHandler $sock]
}
socket -server ::connectHandler $myport
# The server also needs an event handler for data
# from the traffic manager.
proc tmReadHandler {} {
global tmsock
global socks
if {[gets $tmsock data] >= 0} {
# have to determine which process the data is for
set port unknown?
set sock $socks($port)
puts $sock $data
}
}
fileevent $tmsock readable [list ::tmReadHandler]
谢谢你,布拉德。我是TCL的新手,所以我将在线查看如何做到这一点。你知道怎么从头开始做吗?有什么建议吗?