Skip to content

Instantly share code, notes, and snippets.

@crosbymichael
Created June 3, 2016 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crosbymichael/aaca1f3d82bc90995045eb6b9f136d53 to your computer and use it in GitHub Desktop.
Save crosbymichael/aaca1f3d82bc90995045eb6b9f136d53 to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"io"
"log"
"os"
"os/exec"
"github.com/docker/containerd/osutils"
"github.com/opencontainers/runc/libcontainer"
)
func main() {
osutils.SetSubreaper(1)
c, err := libcontainer.NewConsole(1000, 1000)
if err != nil {
log.Fatal(err)
}
cmd := exec.Command("runc", "create", "--console", c.Path(), "test")
go io.Copy(os.Stdout, c)
go io.Copy(c, os.Stdin)
if err := cmd.Run(); err != nil {
log.Fatal(err)
}
var s struct {
Pid int `json:"pid"`
}
out, err := exec.Command("runc", "state", "test").CombinedOutput()
if err != nil {
log.Fatal(err)
}
if err := json.Unmarshal(out, &s); err != nil {
log.Fatal(err)
}
cmd = exec.Command("runc", "start", "test")
if err := cmd.Run(); err != nil {
log.Fatal(err)
}
p, err := os.FindProcess(s.Pid)
if err != nil {
log.Fatal(err)
}
p.Wait()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment