duane9322 2016-05-24 18:00
浏览 19

runc容器启动golang分离模式

I'm testing runc container start time using an automatic go lang script my code is like below and it keep blocking the process even that it runs without blocking in shell.

    command := exec.Command("runc","start","-d","redis")
    command.Dir = "/containers/redis"
    start := time.Now() 
    r,err:=command.CombinedOutput()
    duration:= time.Since(start)/time.Millisecond
    fmt.Println(duration)   
    fmt.Println(err) 
    fmt.Println(string(r))
  • 写回答

1条回答 默认 最新

  • dongpi3237 2019-01-02 22:54
    关注

    When you start a subprocess from sh, it waits for the child process to exit (using something like waitpid()), and then immediately returns. The stdout and stderr of the subprocess (and all its children) will be written directly to your terminal (not via sh), even after sh has returned to the prompt. This is also what .Start() would do.

    When you use .CombinedOutput(), you wait until the stdout and stderr of the started process (and all subprocesses that inherit it) get closed. Even if your immediate child process (runc start) exits, the container it starts might still have a copy of the stdout and stderr and be writing to them, so .CombinedOutput() can't return until it's sure all copies of those files are closed.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度