<p>I have used golang.org/x/sys/unix and exec.Command, but i have noticed no interruption.</p>
<p>Actually, i used "golang.org/x/sys/unix" because it provides RLIMIT_RTTIME that it missing in the default golang syscalls.</p>
<pre><code>// ...
var rTimeLimit syscall.Rlimit
rTimeLimit.Max = 1000
rTimeLimit.Cur = 1000
err := syscall.Setrlimit(unix.RLIMIT_RTTIME, &rTimeLimit)
if err != nil {
fmt.Println("Error Setting Rlimit ", err)
}
cmd := exec.Command(args[0], args[1:]...)
cmd.Dir = workDir
cmd.Stdin = strings.NewReader(stdin)
err = cmd.Run()
// ...
</code></pre>
<p>I was using exec.Command to run the following python snippet :</p>
<pre><code>import time
print("Test")
time.sleep(5)
</code></pre>
<p>Appreciate your interaction.</p>
<hr/>**评论:**<br/><br/>Justinsaccount: <pre><p>I don't think RLIMIT_RTTIME does what you think it does.</p>
<p>What are you actually trying to do?</p></pre>CipheredBytes: <pre><p>Actually, i was trying to limit the execution time of the process run with cmd.Run().</p>
<p>Am i missing something ?</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传