os.Exitos.Exec
os.Exec
packagemain

import (
    "fmt"
    "os"
    "os/exec"
)

func main() {
    fmt.Println("Restarting program...")
    cmd := exec.Command(os.Args[0], os.Args[1:]...)
    err := cmd.Start()
    if err != nil {
        fmt.Printf("Error restarting program: %v\n", err)
        return
    }
    os.Exit(0)
}
os.Exec