osex

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 23, 2022 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OSWindows   = "windows"
	OSDarwin    = "darwin"
	OSDragonfly = "dragonfly"
	OSFreebsd   = "freebsd"
	OSLinux     = "linux"
	OSNacl      = "nacl"
	OSNetbsd    = "netbsd"
	OSOpenbsd   = "openbsd"
	OSSolaris   = "solaris"
)

These are the names of the operating systems recognized by Go.

Variables

View Source
var CurrentPID = os.Getpid()

CurrentPID returns the process id of the caller.

OSUnix is the list of unix-like operating systems recognized by Go. See http://golang.org/src/path/filepath/path_unix.go.

Functions

func ExecCmd added in v0.0.8

func ExecCmd(name string, params ...string) (string, string, error)

func FreeOS

func FreeOS()

func GetCPUNum added in v0.0.6

func GetCPUNum() int

GetCPUNum gets current os's cpu number

func GetCgroupMemoryLimit added in v0.0.6

func GetCgroupMemoryLimit() (uint64, error)

GetCgroupMemoryLimit returns a container's total memory in bytes

func GetCgroupProcessMemoryPercent added in v0.0.6

func GetCgroupProcessMemoryPercent() (float64, error)

GetCgroupProcessMemoryPercent gets current process's memory usage percent in cgroup env

func GetExePath added in v0.0.5

func GetExePath() (exePath string, err error)

func GetFirstGopath added in v0.0.9

func GetFirstGopath(allowAutomaticGuessing bool) (gopath string, err error)

GetFirstGopath gets the first $GOPATH value.

func GetGoPath added in v0.0.9

func GetGoPath() []string

GetGopaths returns the list of Go path directories.

func GetGoroutineNum added in v0.0.6

func GetGoroutineNum() int

GetGoroutineNum gets current process's goroutine number

func GetHostname

func GetHostname() string

GetHostname 获取主机名

func GetMemoryStat added in v0.0.6

func GetMemoryStat() (total, used, free uint64, usedPercent float64)

func GetProcessCPUStat added in v0.0.6

func GetProcessCPUStat() (float64, error)

GetProcessCPUStat gets current process's cpu stat

func GetProcessMemoryPercent added in v0.0.6

func GetProcessMemoryPercent() (float32, error)

GetProcessMemoryStat gets current process's memory usage percent

func GetProcessMemoryStat added in v0.0.6

func GetProcessMemoryStat() (uint64, error)

GetProcessMemoryStat gets current process's memory usage in Byte

func GetRoutineId

func GetRoutineId() uint64

func GetThreadNum added in v0.0.6

func GetThreadNum() int

func GetWorkDir added in v0.0.5

func GetWorkDir() string

获取程序运行目录

func Gid added in v0.1.1

func Gid() (id int64)

func GoRoutine

func GoRoutine(function func())

func GoRoutineInLoop

func GoRoutineInLoop(function func())

func GoRoutineInTimer

func GoRoutineInTimer(duration time.Duration, function func())

func GoSafely added in v0.0.6

func GoSafely(wg *sync.WaitGroup, ignoreRecover bool, handler func(), catchFunc func(r interface{}))

GoSafely wraps a `go func()` with recover()

func GoUnterminated added in v0.0.6

func GoUnterminated(handle func(), wg *sync.WaitGroup, ignoreRecover bool, period time.Duration)

GoUnterminated is used for which goroutine wanna long live as its process. @period: sleep time duration after panic to defeat @handle panic so frequently. if it is not positive,

the @handle will be invoked asap after panic.

func GoVarLoop

func GoVarLoop(n uint64, function func())

func InitFreeOS added in v0.0.7

func InitFreeOS()

func IsCgroup added in v0.0.6

func IsCgroup() bool

IsCgroup checks whether current os is a container or not

func IsLittleEndian

func IsLittleEndian() bool

func OSIsUnix added in v0.0.7

func OSIsUnix(os string) bool

OSIsUnix determines whether or not the given OS name is one of the unix-like operating systems recognized by Go.

func RegisterSignalForPrintStack

func RegisterSignalForPrintStack(sig os.Signal, callback func([]byte))

func RegisterSignalForProfiling

func RegisterSignalForProfiling(sig ...os.Signal)

func Reload

func Reload() error

func SwapEndianUin32

func SwapEndianUin32(val uint32) uint32

Types

type OSMemStats added in v0.0.7

type OSMemStats struct {
	SwapTotal       uint64
	SwapUsed        uint64
	SwapFree        uint64
	SwapUsedPercent float64
	SwapIn          uint64
	SwapOut         uint64

	MemTotal       uint64
	MemAvailable   uint64
	MemUsed        uint64
	MemUsedPercent float64
	MemBuffers     uint64
	MemCached      uint64
}

func GetOsMemStats added in v0.0.7

func GetOsMemStats() (OSMemStats, error)

type Result added in v0.0.8

type Result struct {
	// contains filtered or unexported fields
}

Result cmd exec result

func Run added in v0.0.8

func Run(cmdLine string, timeout ...time.Duration) *Result

Run exec cmd and catch the result. Waits for the given command to finish with a timeout. If the command times out, it attempts to kill the process.

func (*Result) Err added in v0.0.8

func (r *Result) Err() error

Err returns the error log.

func (*Result) String added in v0.0.8

func (r *Result) String() string

String returns the exec log.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL