How to Set and Read GOMAXPROCS, GOGC, GOTRACEBACK

Set GOMAXPROCS, GOGC, and GOTRACEBACK via environment variables or runtime functions to control CPU usage, garbage collection, and panic tracebacks in Go.

Set GOMAXPROCS, GOGC, and GOTRACEBACK using environment variables before running your Go program, or adjust them at runtime via the runtime package. Use go env to inspect current settings and runtime.GOMAXPROCS() or runtime.SetGCPercent() to read or modify values in code.

export GOMAXPROCS=4
export GOGC=200
export GOTRACEBACK=system

# Read current values
runtime.GOMAXPROCS(0)      # Returns current GOMAXPROCS
runtime.SetGCPercent(200)  # Sets GOGC (returns old value)

# Inspect environment
env | grep -E 'GOMAXPROCS|GOGC|GOTRACEBACK'

Note: GOTRACEBACK is only settable via environment variable; it cannot be changed at runtime.