@jsh/process
Since v8.0.52The @jsh/process
module is specifically designed for use in JSH applications
and is not available in the SCRIPT()
function within TQL, unlike other JSH modules.
pid()
Get the process id of the current process.
Syntax
pid()
Parameters
None.
Return value
A number value that represents the process ID.
Usage example
|
|
ppid()
Get the process id of the parent process.
Syntax
ppid()
Parameters
None.
Return value
A number value that represents the parent process ID.
Usage example
|
|
args()
Get command line arguments
Syntax
args()
Parameters
None.
Return value
String[]
Usage example
|
|
cwd()
Get the current working directory
Syntax
cwd()
Parameters
None.
Return value
String
Usage example
|
|
cd()
Change the current working directory.
Syntax
cd(path)
Parameters
path
: directory path to move
Return value
None.
Usage example
|
|
readDir()
Read files and sub-directories of the given directory.
Syntax
readDir(path, callback)
Parameters
path
:String
path to the directorycallback
: function (DirEntry) [undefined|Boolean] callback function. if it returns false, the iteration will stop.
Return value
None.
Usage example
|
|
DirEntry
Property | Type | Description |
---|---|---|
name | String | |
isDir | Boolean | |
readOnly | Boolean | |
type | String | |
size | Number | |
virtual | Boolean |
print()
Write arguments into the output, the default output is the log file or stdout if log filename is not set.
Syntax
print(...args)
Parameters
args
...any
Variable length of argument to write.
Return value
None.
Usage example
|
|
exec()
Run another JavaScript application.
Syntax
exec(cmd, ...args)
Parameters
cmd
String
.js file path to run
args
...String
arguments to pass to the cmd.
Return value
None.
Usage example
|
|
daemonize()
Run the current script file as a daemon process with its parent process ID set to 1
.
Syntax
daemonize()
Parameters
None.
Return value
None.
Usage example
|
|
sleep()
Pause the current control flow.
This function is provided in the process module for convenience and has an equivalent in the @jsh/system
module.
Syntax
sleep(sec)
Parameters
sec
Number
sleep duration in seconds.
Return value
None.
Usage example
|
|
kill()
Terminate a process using the specified process ID (pid).
Syntax
kill(pid)
Parameters
pid
Number
pid of target process.
Return value
None.
Usage example
|
|
ps()
List all currently running processes.
Syntax
ps()
Parameters
None.
Return value
Process[]
: Array of Process objects.
Usage example
|
|
Process
Process information that returned by ps()
.
Properties
Property | Type | Description |
---|---|---|
pid | Number | process ID |
ppid | Number | process ID of the parent |
user | String | username (e.g: sys ) |
name | String | Script file name |
uptime | String | Elapse duration since started |
addCleanup()
Add a function to execute when the current JavaScript VM terminates.
Syntax
addCleanup(fn)
Parameters
fn
()=>{}
callback function
Return value
Number
A token for remove the cleanup callback.
Usage example
|
|
removeCleanup()
Remove a previously registered cleanup callback using the provided token.
Syntax
removeCleanup(token)
Parameters
token
Number
token that returned by addCleanup()
.
Return value
None.
Usage example
|
|