Source file src/os/executable_procfs.go

     1  // Copyright 2016 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build linux || netbsd
     6  
     7  package os
     8  
     9  import (
    10  	"errors"
    11  	"internal/stringslite"
    12  	"runtime"
    13  )
    14  
    15  func executable() (string, error) {
    16  	var procfn string
    17  	switch runtime.GOOS {
    18  	default:
    19  		return "", errors.New("Executable not implemented for " + runtime.GOOS)
    20  	case "linux", "android":
    21  		procfn = "/proc/self/exe"
    22  	case "netbsd":
    23  		procfn = "/proc/curproc/exe"
    24  	}
    25  	path, err := Readlink(procfn)
    26  
    27  	// When the executable has been deleted then Readlink returns a
    28  	// path appended with " (deleted)".
    29  	return stringslite.TrimSuffix(path, " (deleted)"), err
    30  }
    31  

View as plain text