<p>I wanted to write a simple function that receives a PID number and then checks if a process is still running or not in windows.</p>
<p>Is there a simple way to do this in Windows? some articles seem to give the idea that you need to read the entire process table (CreateToolhelp32Snapshot IIRC) but I thought it may be a simpler solution if you already have the process ID.</p>
<hr/>**评论:**<br/><br/>distrus: <pre><p>You can try to use <a href="https://godoc.org/os#FindProcess" rel="nofollow">os.FindProcess</a>. I remember using it for this exact purpose, so I'm pretty sure this should work. The caveat of this method is </p>
<blockquote>
<p>On Unix systems, FindProcess always succeeds and returns a Process for the given pid, regardless of whether the process exists.</p>
</blockquote>
<p>But since you're on Windows this shouldn't concern you too much.</p></pre>youguess: <pre><blockquote>
<blockquote>
<p>On Unix systems, FindProcess always succeeds and returns a Process for the given pid, regardless of whether the process exists.</p>
</blockquote>
</blockquote>
<p>Why on Earth would they do that? Why not return an error?</p></pre>SaturnsVoid: <pre><p>Could use WMI, github.com/StackExchange/wmi</p></pre>SebGo: <pre><p>Call with exec.Command:</p>
<p>tasklist /FI " PID eq 1234"</p>
<p>and parse output.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传