github.com/karrick/go@v0.0.0-20170817181416-d5b0ec858b37/src/os/proc.go (about)

     1  // Copyright 2009 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  // Process etc.
     6  
     7  package os
     8  
     9  import (
    10  	"runtime"
    11  	"syscall"
    12  )
    13  
    14  // Args hold the command-line arguments, starting with the program name.
    15  var Args []string
    16  
    17  func init() {
    18  	if runtime.GOOS == "windows" {
    19  		// Initialized in exec_windows.go.
    20  		return
    21  	}
    22  	Args = runtime_args()
    23  }
    24  
    25  func runtime_args() []string // in package runtime
    26  
    27  // Getuid returns the numeric user id of the caller.
    28  //
    29  // On Windows, it returns -1.
    30  func Getuid() int { return syscall.Getuid() }
    31  
    32  // Geteuid returns the numeric effective user id of the caller.
    33  //
    34  // On Windows, it returns -1.
    35  func Geteuid() int { return syscall.Geteuid() }
    36  
    37  // Getgid returns the numeric group id of the caller.
    38  //
    39  // On Windows, it returns -1.
    40  func Getgid() int { return syscall.Getgid() }
    41  
    42  // Getegid returns the numeric effective group id of the caller.
    43  //
    44  // On Windows, it returns -1.
    45  func Getegid() int { return syscall.Getegid() }
    46  
    47  // Getgroups returns a list of the numeric ids of groups that the caller belongs to.
    48  //
    49  // On Windows, it returns syscall.EWINDOWS. See the os/user package
    50  // for a possible alternative.
    51  func Getgroups() ([]int, error) {
    52  	gids, e := syscall.Getgroups()
    53  	return gids, NewSyscallError("getgroups", e)
    54  }
    55  
    56  // Exit causes the current program to exit with the given status code.
    57  // Conventionally, code zero indicates success, non-zero an error.
    58  // The program terminates immediately; deferred functions are not run.
    59  func Exit(code int) {
    60  	if code == 0 {
    61  		// Give race detector a chance to fail the program.
    62  		// Racy programs do not have the right to finish successfully.
    63  		runtime_beforeExit()
    64  	}
    65  	syscall.Exit(code)
    66  }
    67  
    68  func runtime_beforeExit() // implemented in runtime