Skip to main content

Read sysctl Key (sys.ctlbyname)

Declaration

data = sys.ctlbyname(key)

Parameters

  • key
    String. Full sysctl key name, for example kern.boottime or hw.memsize.

Returns

  • data
    String. Raw byte data returned by the key. Returns nil when the key cannot be read.

Description

Calls the underlying sysctlbyname to fetch kernel or hardware runtime parameters.
Use this to retrieve sysctl values, inspect kernel state, or capture metrics. The raw data often needs additional unpacking.

Examples

local raw = sys.ctlbyname('hw.machine')
if type(raw) == 'string' then
nLog('Device type: '..raw:gsub('%z+$', ''))
else
nLog('Failed to read hw.machine')
end

local sec, usec = string.unpack('li', sys.ctlbyname('kern.boottime'))
nLog('Seconds since boot', os.time() - sec)