osKit

package
v2.2.33 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PathSeparator 路径分隔符(string类型)
	/*
		e.g. Mac
		"/"
	*/
	PathSeparator = string(os.PathSeparator)

	// PathListSeparator 路径列表分隔符(string类型)
	/*
		e.g. Mac
		":"
	*/
	PathListSeparator = string(os.PathListSeparator)
)

Variables

View Source
var ARCH string

ARCH 处理器架构

View Source
var BITS int

BITS 操作系统的位数(32 || 64)

参考: Go获取操作系统位数 https://blog.csdn.net/TCatTime/article/details/106815724

View Source
var GetGoroutineCount func() int = runtime.NumGoroutine

GetGoroutineCount 当前进程中的协程数.

OS 操作系统

Functions

func ExitWithCode

func ExitWithCode(code int)

ExitWithCode 退出程序

PS: 无论是在main程还是子程中,只要调用os.Exit(),程序就会终止.

@param code 0:正常退出;非0:非正常退出(一般用1)

func GetCoreFileSize added in v2.1.32

func GetCoreFileSize() (string, error)

GetCoreFileSize 获取: core文件的最大值,单位为区块.

func GetEnv

func GetEnv(key string, defArgs ...string) string

GetEnv (带默认值地)获取系统环境变量.

@param key 可以为"" @return 可能为""

e.g. ("") => "" ("JAVA_HOME") => "/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home"

func GetMaxMapCount added in v2.1.32

func GetMaxMapCount() (int, error)

GetMaxMapCount 获取: 一个进程可以拥有的最大内存映射区域数量(间接限制了线程数).

PS: @return 间接限制了线程数,因为每个线程都需要一些内存映射区域.

命令: cat /proc/sys/vm/max_map_count sysctl vm.max_map_count

func GetMaxOpenFiles

func GetMaxOpenFiles() (int, error)

GetMaxOpenFiles 获取: 同一时间最多可开启的文件数.

PS: (1) 当前仅支持Mac、Linux环境. (2) 为何使用 sh -c "ulimit -n" 而非 ulimit -n? https://www.thinbug.com/q/17483723

func GetMaxProcessThreadCountByUser added in v2.1.40

func GetMaxProcessThreadCountByUser() (int, error)

GetMaxProcessThreadCountByUser 获取: 单个用户可以创建的进程数上限(线程也算)

PS: (1) ulimit -u命令: 限制单个用户可以创建的进程数. (2) ulimit -u命令也可以用来限制单个用户可以创建的线程数,因为: 在Linux中,线程本质上只是具有共享地址空间的进程。

func GetPidMax added in v2.1.32

func GetPidMax() (int, error)

GetPidMax 获取: 系统的pid最大值(作为系统范围内 进程 和 线程 总数的限制).

PS: (1) 大多数Linux上的默认值: 32768

32位系统: 最大值为 32768
64位系统: 任何小于等于 2^22(PID_MAX_LIMIT,约 400 万)的值

命令: cat /proc/sys/kernel/pid_max sysctl kernel.pid_max

func GetThreadsMax added in v2.1.32

func GetThreadsMax() (int, error)

GetThreadsMax 获取: 系统的最大线程数.

命令: cat /proc/sys/kernel/threads-max sysctl kernel.threads-max

func GetUlimitInfo added in v2.1.32

func GetUlimitInfo() (string, error)

GetUlimitInfo 获取: 目前资源限制的信息.

命令: sh -c "ulimit -a"

func IsLinux

func IsLinux() bool

func IsMac

func IsMac() bool

func IsWindows

func IsWindows() bool

func SetEnvs

func SetEnvs(m map[string]string) error

SetEnvs 一次性设置多个系统变量.

@param m 可以为nil @return 如果发生error的话,返回第一个

Types

This section is empty.

Jump to

Keyboard shortcuts

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