Modules@robinpath/process
process

@robinpath/process

0.1.2Node.jsPublic

Child process management: run commands, spawn long-running processes, get system info

Process

Child process management: run commands, spawn long-running processes, get system info

Package: @robinpath/process | Category: Infrastructure | Type: Utility

Authentication

No authentication required. All functions are available immediately.

Use Cases

Use the process module when you need to:

  • Run command and wait for result -- Use process.run to perform this operation
  • Execute command in shell -- Use process.exec to perform this operation
  • Spawn long-running process -- Use process.spawn to perform this operation
  • Kill a spawned process -- Use process.kill to perform this operation
  • Check if process is running -- Use process.isAlive to perform this operation

Quick Reference

FunctionDescriptionReturns
runRun command and wait for result{stdout, stderr, code}
execExecute command in shell{stdout, stderr}
spawnSpawn long-running processProcess id
killKill a spawned processtrue
isAliveCheck if process is runningtrue if running
listList all managed processesArray of {id, pid, running}
signalSend signal to processtrue
pidGet current process PIDPID
uptimeGet process uptime in secondsUptime seconds
memoryUsageGet memory usage in MB{rss, heapTotal, heapUsed, external}
cpuUsageGet CPU usage in ms{user, system}
cwdGet working directoryCurrent directory path
argvGet process argumentsArgument strings
envGet environment variablesAll env vars
exitRequest process exit (safe, does not actually exit){exitCode, note}

Functions

run

Run command and wait for result

Module: process | Returns: object -- {stdout, stderr, code}

process.run "ls -la"
ParameterTypeRequiredDescription
commandstringYesShell command
optionsobjectNo{cwd, env, timeout, shell}

exec

Execute command in shell

Module: process | Returns: object -- {stdout, stderr}

process.exec "echo hello"
ParameterTypeRequiredDescription
commandstringYesShell command
optionsobjectNo{cwd, env, timeout, maxBuffer}

spawn

Spawn long-running process

Module: process | Returns: string -- Process id

process.spawn "server" "node" ["app.js"]
ParameterTypeRequiredDescription
idstringYesProcess identifier
commandstringYesCommand to run
argsarrayNoCommand arguments
optionsobjectNo{cwd, env, shell, detached}

kill

Kill a spawned process

Module: process | Returns: boolean -- true

process.kill "server"
ParameterTypeRequiredDescription
idstringYesProcess id
signalstringNoSignal (default SIGTERM)

isAlive

Check if process is running

Module: process | Returns: boolean -- true if running

process.isAlive "server"
ParameterTypeRequiredDescription
idstringYesProcess id

list

List all managed processes

Module: process | Returns: array -- Array of {id, pid, running}

process.list
ParameterTypeRequiredDescription
(none)NoCall with no arguments

signal

Send signal to process

Module: process | Returns: boolean -- true

process.signal "server" "SIGUSR1"
ParameterTypeRequiredDescription
idstringYesProcess id
signalstringYesSignal name

pid

Get current process PID

Module: process | Returns: number -- PID

process.pid
ParameterTypeRequiredDescription
(none)NoCall with no arguments

uptime

Get process uptime in seconds

Module: process | Returns: number -- Uptime seconds

process.uptime
ParameterTypeRequiredDescription
(none)NoCall with no arguments

memoryUsage

Get memory usage in MB

Module: process | Returns: object -- {rss, heapTotal, heapUsed, external}

process.memoryUsage
ParameterTypeRequiredDescription
(none)NoCall with no arguments

cpuUsage

Get CPU usage in ms

Module: process | Returns: object -- {user, system}

process.cpuUsage
ParameterTypeRequiredDescription
(none)NoCall with no arguments

cwd

Get working directory

Module: process | Returns: string -- Current directory path

process.cwd
ParameterTypeRequiredDescription
(none)NoCall with no arguments

argv

Get process arguments

Module: process | Returns: array -- Argument strings

process.argv
ParameterTypeRequiredDescription
(none)NoCall with no arguments

env

Get environment variables

Module: process | Returns: object -- All env vars

process.env
ParameterTypeRequiredDescription
(none)NoCall with no arguments

exit

Request process exit (safe, does not actually exit)

Module: process | Returns: object -- {exitCode, note}

process.exit 0
ParameterTypeRequiredDescription
codenumberNoExit code (default 0)

Error Handling

All functions throw on failure. Common errors:

ErrorCause
Process "..." already existsCheck the error message for details
Process "..." not foundCheck the error message for details
@desc "Run and validate result"
do
  set $result as process.run "ls -la"
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. List and iterate

Retrieve all items and loop through them.

@desc "List and iterate results"
do
  set $result as process.list
  each $item in $result
    print $item
  end
enddo

2. Multi-step Process workflow

Chain multiple process operations together.

@desc "Run, exec, and more"
do
  set $r_run as process.run "ls -la"
  set $r_exec as process.exec "echo hello"
  set $r_spawn as process.spawn "server" "node" ["app.js"]
  print "All operations complete"
enddo

3. Safe run with validation

Check results before proceeding.

@desc "Run and validate result"
do
  set $result as process.run "ls -la"
  if $result != null
    print "Success: " + $result
  else
    print "Operation returned no data"
  end
enddo

Related Modules

  • json -- JSON module for complementary functionality

Versions (1)

VersionTagPublished
0.1.2latest1 months ago
Install
$ robinpath add @robinpath/process

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.2
LicenseMIT
Unpacked Size5.1 KB
Versions1
Weekly Downloads21
Total Downloads21
Stars0
Last Publish1 months ago
Created1 months ago

Category

devops