Instantly share code, notes, and snippets.

Embed
What would you like to do?
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