[Q] How can i use golang.org/x/sys/unix with exec.Command ?

agolangf · · 596 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I have used golang.org/x/sys/unix and exec.Command, but i have noticed no interruption.</p> <p>Actually, i used &#34;golang.org/x/sys/unix&#34; 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, &amp;rTimeLimit) if err != nil { fmt.Println(&#34;Error Setting Rlimit &#34;, 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(&#34;Test&#34;) time.sleep(5) </code></pre> <p>Appreciate your interaction.</p> <hr/>**评论:**<br/><br/>Justinsaccount: <pre><p>I don&#39;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

596 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传