os + runtime)Python’s sys maps to several Go packages: os for argv/env/exit, runtime for interpreter-like introspection.
import "os"
for i, a := range os.Args {
_, _ = i, a
}
os.Stdin
os.Stdout
os.Stderr
runtimeimport "runtime"
n := runtime.NumCPU()
runtime.GOMAXPROCS(n)
var m runtime.MemStats
runtime.ReadMemStats(&m)
println(runtime.Version()) // Go version
buf := make([]byte, 1<<20)
n := runtime.Stack(buf, true) // all goroutines if true
println(string(buf[:n]))
log.FatalCalls os.Exit(1) after printing — defers in main won’t run.
runtime/debug.ReadBuildInfo() in binaries built as modules exposes module versions.