package main import ( "time" "net/http" "net/http/pprof" "strconv" "os" "net" ) func main() { ListenPprof() go foo() time.Sleep(1*time.Hour) } func foo() { a := make(chan struct{}) select { case <-a: } _ = 0 } func ListenPprof() { path := "@/pprof/" + strconv.Itoa(os.Getpid()) l, err := net.Listen("unix", path) if err != nil { panic(err) } mux := http.NewServeMux() mux.Handle("/debug/pprof/", http.HandlerFunc(pprof.Index)) mux.Handle("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline)) mux.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile)) mux.Handle("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol)) // ignore errors from Serve go http.Serve(l, mux) }