syscall

Guided tour · Misc · pkg.go.dev →

Low-level, platform-specific OS primitives. Frozen — prefer os, os/exec, and golang.org/x/sys for anything new.

Common uses

Set file permissions precisely

syscall.Umask(0o077) // affects os.Create / OpenFile defaults

Process attributes (Unix)

cmd := exec.Command("srv")
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
cmd.Start()

Signals

syscall.Kill(pid, syscall.SIGTERM)

Errno

_, err := os.Open("x")
if errors.Is(err, syscall.ENOENT) { /* missing file */ }

Note

New OS features land in golang.org/x/sys, not here. Use this package only when you can't avoid it.