osKit

package
v3.0.81 Latest Latest
Warning

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

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

Documentation

Index

Constants

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

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

Variables

View Source
var (
	// IsWindows 检查当前操作系统是否是windows
	IsWindows func() bool = system.IsWindows

	// IsLinux 检查当前操作系统是否是linux.
	IsLinux func() bool = system.IsLinux

	// IsMac 检查当前操作系统是否是macos.
	IsMac func() bool = system.IsMac
)

ARCH 处理器架构

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

func GetCoreFileSize() (string, error)

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

func GetMaxMapCount

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

func GetMaxProcessThreadCountByUser() (int, error)

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

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

func GetOsBits

func GetOsBits() int

GetOsBits 获取当前操作系统位数,返回32或64.

@return 32 || 64

func GetPidMax

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

func GetThreadsMax() (int, error)

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

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

func GetUlimitInfo

func GetUlimitInfo() (string, error)

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

命令: sh -c "ulimit -a"

Types

This section is empty.

Jump to

Keyboard shortcuts

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