os
The os module provides Node.js-compatible operating system information APIs for JSH applications.
arch()
Returns CPU architecture.
Syntax
arch()Usage example
| |
platform()
Returns platform name such as darwin, linux, or windows.
Syntax
platform()Usage example
| |
type()
Returns OS type such as Darwin, Linux, or Windows_NT.
Syntax
type()Usage example
| |
release()
Returns kernel release/version string.
Syntax
release()Usage example
| |
hostname()
Returns host name.
Syntax
hostname()Usage example
| |
homedir()
Returns current user home directory.
Syntax
homedir()Usage example
| |
tmpdir()
Returns the default temporary directory path.
Syntax
tmpdir()Usage example
| |
endianness()
Returns CPU endianness: BE or LE.
Syntax
endianness()Usage example
| |
EOL
Platform-specific end-of-line marker.
- POSIX:
\n - Windows:
\r\n
Usage example
| |
totalmem(), freemem()
Returns total/free memory in bytes.
Syntax
totalmem()
freemem()Usage example
| |
uptime()
Returns system uptime in seconds.
Syntax
uptime()Usage example
| |
bootTime()
Returns system boot time as Unix timestamp.
Syntax
bootTime()Usage example
| |
loadavg()
Returns load averages as [1min, 5min, 15min].
Syntax
loadavg()Usage example
| |
cpus()
Returns per-CPU information array.
Each item includes fields like:
model,speed,coresvendor,family,model,steppingtimes.user,times.nice,times.sys,times.idle,times.irq(milliseconds)
Syntax
cpus()Usage example
| |
cpuCounts()
Returns CPU count.
true: logical CPU countfalse: physical CPU count
Syntax
cpuCounts(logical)Usage example
| |
cpuPercent()
Returns CPU usage percentages.
intervalSec: sampling interval in seconds (0for immediate)perCPU: return per-core values whentrue
Syntax
cpuPercent(intervalSec, perCPU)Usage example
| |
networkInterfaces()
Returns network interface information object.
The object shape is:
- key: interface name
- value: array of address objects
addressfamily(IPv4/IPv6)internal(boolean)
Syntax
networkInterfaces()Usage example
| |
hostInfo()
Returns host information object.
Common fields include:
hostname,uptime,bootTime,procsos,platform,platformFamily,platformVersionkernelVersion,kernelArchvirtualizationSystem,virtualizationRole,hostId
Syntax
hostInfo()Usage example
| |
userInfo()
Returns current user information.
Returned fields include:
username,homedir,shelluid,gid
Syntax
userInfo([options])Usage example
| |
diskPartitions()
Returns disk partition list.
Syntax
diskPartitions([all])Usage example
| |
diskUsage()
Returns disk usage for the given path.
Typical fields include total, used, free, usedPercent.
Syntax
diskUsage(path)Usage example
| |
diskIOCounters()
Returns disk I/O counters.
namesomitted or empty: all devicesnamesspecified: selected devices
Syntax
diskIOCounters([names])Usage example
| |
netProtoCounters()
Returns network protocol counters.
Syntax
netProtoCounters([proto])Usage example
| |
constants
An object that contains operating system related constants.
It currently provides the following child objects.
os.constants.signalsos.constants.priority
Usage example
| |
os.constants.signals
An object that provides signal names and their numeric values.
These constants use canonical Unix-style signal numbers for API compatibility. On Windows, not every numeric value maps to a distinct native signal behavior.
For example, it includes entries such as:
| Literal | Number |
|---|---|
SIGHUP | 1 |
SIGINT | 2 |
SIGQUIT | 3 |
SIGABRT | 6 |
SIGKILL | 9 |
SIGUSR1 | 10 |
SIGSEGV | 11 |
SIGUSR2 | 12 |
SIGPIPE | 13 |
SIGALRM | 14 |
SIGTERM | 15 |
These values can be passed to process.kill() as numeric signals.
On Windows, SIGINT is treated specially.
JSH attempts to deliver it as an interrupt-style console control event, which is the closest available equivalent.
By contrast, SIGTERM, SIGQUIT, and SIGKILL behave as termination requests on Windows.
Usage example
| |
Relationship With The process Signal API
os.constants.signals provides signal numbers, while the actual signal handling and delivery are performed by the process module.
- receive a signal:
process.on('SIGINT', handler) - send a signal:
process.kill(pid, os.constants.signals.SIGTERM)
process.on() accepts case-insensitive signal names, but signal event names must still use the canonical SIG-prefixed form such as SIGINT or sigint.
Bare aliases such as term are not signal listener names.
process.kill() is more permissive and accepts aliases such as term in addition to canonical names.
By contrast, os.constants.signals exposes canonical constant names only.
On Windows, process.kill(pid, os.constants.signals.SIGINT) is best-effort and depends on Windows console routing rules.
Usage example
| |
os.constants.priority
An object that defines process priority levels.
Main fields
| Constant | Meaning |
|---|---|
PRIORITY_LOW | low priority |
PRIORITY_BELOW_NORMAL | below-normal priority |
PRIORITY_NORMAL | normal default priority |
PRIORITY_ABOVE_NORMAL | above-normal priority |
PRIORITY_HIGH | high priority |
PRIORITY_HIGHEST | highest priority |
Usage example
| |