gpt4 book ai didi

tcl - windows环境下TCL如何杀死后台进程

转载 作者:行者123 更新时间:2023-12-04 14:40:46 24 4
gpt4 key购买 nike

我已经在 Windows 环境中使用 Tcl 的 exec 命令从 Tcl 程序中将 iperf 作为后台进程启动。但是,我想在将来的任意时间以编程方式从同一个 Tcl 程序中终止 iperf 进程。我怎样才能最好地做到这一点?

这是我正在使用的代码

proc runtest {  REF_WLAN_IPAddr run_time} {
exec c:\\iperf_new\\iperf -c $REF_WLAN_IPAddr -f m -w 2M -i 1 -t $run_time >& xx.txt &
# have some code after this
}

但我看到 iperf 没有被杀死,所以控制权没有转移回 TCL,我该怎么做?高度赞赏答案

最佳答案

exec 如果按照您描述的方式使用,则返回子进程 PID 列表,但是 Tcl 没有内置的 kill 命令;这些仅在扩展中可用。

所以你有两个主要选择:

  1. 获取 TWAPI 包 http://twapi.magicsplat.com/并使用该包中的 end_process 函数(参见 http://twapi.magicsplat.com/process.html#end_process )

  2. 使用第二个 exec 并使用/PID 选项运行 windows 命令 taskkill

    exec [auto_execok taskkill] /PID $pid

关于tcl - windows环境下TCL如何杀死后台进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9400130/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com