process
The process module is specifically designed for use in JSH applications.
env
The JSH runtime environment object.
Usage example
| |
execPath
The absolute file path to the executable file of the current process on the host operating system.
Usage example
| |
pid
The process ID of the current process. The value type is number and represents the process ID.
Usage example
| |
ppid
The process ID of the parent process. The value type is number and represents the parent process ID.
Usage example
| |
platform
A string that identifies the operating system platform of the host machine. Common values include windows, linux, and darwin (macOS).
Usage example
| |
arch
A string that identifies the operating system architecture of the host machine.
Common values include amd64, aarch64.
Usage example
| |
version
A string that identifies the JSH runtime version.
Usage example
| |
versions
An object that provides detailed runtime version information.
versions.jsh: JSH runtime version stringversions.go: Go runtime version string
Usage example
| |
title
A string that identifies the current program.
Usage example
| |
stdin, stdout, stderr
Streams for stdin, stdout, and stderr.
Usage example
| |
addShutdownHook()
Add a callback function that will be called at the termination of the current process.
Syntax
addShutdownHook(()=>{})Usage example
| |
exit()
Exit the current process. If the code is omitted, default is 0.
Syntax
exit([code])Usage example
| |
which()
Finds a JavaScript command in PATH and returns the resolved file path.
If the command does not include .js, it is added automatically.
Syntax
which(command)Usage example
| |
expand()
Expands environment variables such as $HOME and ${HOME} in a string.
Syntax
expand(value)Usage example
| |
exec()
Executes a JavaScript command file and returns its exit code.
Syntax
exec(command, ...args)Usage example
| |
execString()
Executes JavaScript source code from a string and returns its exit code.
Syntax
execString(source, ...args)Usage example
| |
dispatchEvent()
Dispatches an event to an event emitter object on the JSH event loop.
This function returns true if the event is scheduled, false if the event loop is already terminated.
Syntax
dispatchEvent(target, eventName, ...args)Usage example
| |
now()
Returns the current time as a JavaScript date-time object.
Usage example
| |
chdir()
Changes the current working directory.
If path is empty, JSH resolves it to $HOME.
Syntax
chdir(path)Usage example
| |
cwd()
Returns the current working directory path.
Usage example
| |
nextTick()
Schedules a callback to run on the next event loop turn.
If the first argument is not a function, this call does nothing and returns undefined.
Syntax
nextTick(callback, ...args)Usage example
| |
memoryUsage()
Returns memory usage information as an object.
Current implementation returns placeholder numeric values (0) for all fields.
Returned fields
rssheapTotalheapUsedexternalarrayBuffers
Usage example
| |
cpuUsage()
Returns CPU usage information.
Current implementation returns placeholder numeric values (0) for both fields.
Returned fields
usersystem
Usage example
| |
uptime()
Returns process uptime in seconds as a number.
Usage example
| |
hrtime()
Returns a high-resolution time tuple as [seconds, nanoseconds].
If a previous tuple is provided, it returns the elapsed time from that point.
Syntax
hrtime([previous])Usage example
| |
kill()
Sends a signal request to the given process id.
Current implementation is a placeholder:
- returns an
Errorobject whenpidis missing - returns
truewhenpidis provided (signal defaults toSIGTERM)
Syntax
kill(pid[, signal])Usage example
| |
dumpStack()
Prints the current JavaScript call stack up to the specified depth for debugging.
Syntax
dumpStack(depth)Usage example
| |