github.com/gonutz/osext@v0.0.0-20171206091709-9e22409d6bb6/osext_plan9.go (about)

     1  // Copyright 2012 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  //+build !go1.8
     6  
     7  package osext
     8  
     9  import (
    10  	"os"
    11  	"strconv"
    12  	"syscall"
    13  )
    14  
    15  func executable() (string, error) {
    16  	f, err := os.Open("/proc/" + strconv.Itoa(os.Getpid()) + "/text")
    17  	if err != nil {
    18  		return "", err
    19  	}
    20  	defer f.Close()
    21  	return syscall.Fd2path(int(f.Fd()))
    22  }