Skip to content

Execing processes

syscall.Exec replaces the current Go process with another program (no return). This is rarely used but available for advanced cases.

Replace the current process with /bin/ls.

package main
import (
"syscall"
)
func main() {
binary := "/bin/ls"
args := []string{"ls", "-l"}
env := syscall.Environ()
err := syscall.Exec(binary, args, env)
if err != nil {
panic(err)
}
}
Terminal window
total 0
-rw-r--r-- 1 user staff 0 Jan 1 12:00 file.txt