2013-01-08 65 views
0

我想知道通过tcl编码检索窗口中所有可用pid的方法。这是我需要基于它是否可用而杀死进程? 感谢你。 code:如何检索tcl窗口中所有可用的PID?

proc stopprogressbar {} { 
    variable n_progressWinPid; 
    if {[info exists n_progressWinPid]} { 
    if {$n_progressWinPid > 0} { 
     if {[lsearch [GETALLPIDS] $n_progressWinPid] >= 0} { 
     catch {exec [auto_execok taskkill] /PID $n_progressWinPid} 
     } 
    } 
    } 
} 

回答

4

twapi::get_process_ids返回Windows系统上的所有PID。您必须先登录package require twapi

如果您正在使用ActiveTcl,请在命令提示符下运行C:\Tcl\bin\teacup.exe install twapi(或安装了Tcl的任何位置)以获取TWAPI。它甚至可能被默认包含在新的ActiveTcl版本中,我不知道。

+0

是的...这就是我正在寻找..而我使用了相同的包。 – OliveOne

1

看来你的目标是杀死一个进程,如果存在。如何以任何方式杀死它,而不检查?

package require Tclx;   # For the kill command 
catch {kill $n_progressWinPid}; # Kill the process 

在Tclx软件包,你可能会发现其他有用的命令:

id process;  # Get PID for this process 
id process parent; # Get PID for the parent of this process 
wait ?many options? pid; # Wait for a process 

请查找为Tclx包帮助以获取更多信息。

+0

这是真的,我想最终杀死进程,但在主程序中,我想检查pid(n_progressWinPid)是否存在。这是为了如果该pid不存在,则停止主要过程,否则继续。 (主进程不是突出的单循环) – OliveOne

+0

@OliveOne检查一个进程是否存在最好通过查找目录'/ proc/$ thepid'或通过使用正确的选项运行系统程序'ps'来完成(例如'exec ps -p $ thepid')。唉,由于历史原因,这些都是不可移植的。 –

+0

是的,这将工作在unix *像os,但不是在windows. – OliveOne