Black Lives Matter. Support the Equal Justice Initiative.

Source file src/os/proc.go

Documentation: os

     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  	"internal/testlog"
    11  	"runtime"
    12  	"syscall"
    13  )
    14  
    15  // Args hold the command-line arguments, starting with the program name.
    16  var Args []string
    17  
    18  func init() {
    19  	if runtime.GOOS == "windows" {
    20  		// Initialized in exec_windows.go.
    21  		return
    22  	}
    23  	Args = runtime_args()
    24  }
    25  
    26  func runtime_args() []string // in package runtime
    27  
    28  // Getuid returns the numeric user id of the caller.
    29  //
    30  // On Windows, it returns -1.
    31  func Getuid() int { return syscall.Getuid() }
    32  
    33  // Geteuid returns the numeric effective user id of the caller.
    34  //
    35  // On Windows, it returns -1.
    36  func Geteuid() int { return syscall.Geteuid() }
    37  
    38  // Getgid returns the numeric group id of the caller.
    39  //
    40  // On Windows, it returns -1.
    41  func Getgid() int { return syscall.Getgid() }
    42  
    43  // Getegid returns the numeric effective group id of the caller.
    44  //
    45  // On Windows, it returns -1.
    46  func Getegid() int { return syscall.Getegid() }
    47  
    48  // Getgroups returns a list of the numeric ids of groups that the caller belongs to.
    49  //
    50  // On Windows, it returns syscall.EWINDOWS. See the os/user package
    51  // for a possible alternative.
    52  func Getgroups() ([]int, error) {
    53  	gids, e := syscall.Getgroups()
    54  	return gids, NewSyscallError("getgroups", e)
    55  }
    56  
    57  // Exit causes the current program to exit with the given status code.
    58  // Conventionally, code zero indicates success, non-zero an error.
    59  // The program terminates immediately; deferred functions are not run.
    60  //
    61  // For portability, the status code should be in the range [0, 125].
    62  func Exit(code int) {
    63  	if code == 0 {
    64  		if testlog.PanicOnExit0() {
    65  			// We were told to panic on calls to os.Exit(0).
    66  			// This is used to fail tests that make an early
    67  			// unexpected call to os.Exit(0).
    68  			panic("unexpected call to os.Exit(0) during test")
    69  		}
    70  
    71  		// Give race detector a chance to fail the program.
    72  		// Racy programs do not have the right to finish successfully.
    73  		runtime_beforeExit()
    74  	}
    75  	syscall.Exit(code)
    76  }
    77  
    78  func runtime_beforeExit() // implemented in runtime
    79  

View as plain text