Systems Programming

Systems Programming: Low Level Go

Go was written to replace C++ at Google. It has deep system capabilities.

1. Syscalls (golang.org/x/sys/unix)

Go doesn’t use libc for syscalls (on Linux). It makes raw syscalls. The syscall package is frozen. Use golang.org/x/sys/unix.

// Example: Lock memory to prevent swapping (mlock)
unix.Mlock(data)

2. Debuggers (Delve)

Delve (dlv) is the Go debugger. * Remote Debugging: Run your app on a Linux server, connect your IDE (VS Code) from your Mac. * Core Dumps: If your app crashes in prod, configure it to write a core dump. Open the core dump with Delve to see the exact state of memory when it died.

dlv core ./myapp core.1234

3. eBPF (Cilium/Ebpf)

eBPF is the kernel superpower of 2026. You can write programs that run inside the Linux Kernel to filter packets or trace functions safely.

Go is the primary language for writing eBPF userspace controllers (Cilium, Falco). Library: github.com/cilium/ebpf.

4. unsafe Pointer Magic

Sometimes you need to read a C struct or cast bytes to floats instantly.

import "unsafe"

func BytesToFloat(b []byte) float64 {
    return *(*float64)(unsafe.Pointer(&b[0]))
}

Warning: This is dangerous. It bypasses types. But it’s necessary for zero-copy parsing of network packets or binary formats.