Members
(static) SIGABRT :number
- Source:
- Default Value:
- 6
Type:
- number
(static) SIGALRM :number
- Source:
- Default Value:
- 14
Type:
- number
(static) SIGBUS :number
- Source:
- Default Value:
- 7
Type:
- number
(static) SIGCHLD :number
- Source:
- Default Value:
- 17
Type:
- number
(static) SIGCONT :number
- Source:
- Default Value:
- 18
Type:
- number
(static) SIGFPE :number
- Source:
- Default Value:
- 8
Type:
- number
(static) SIGHUP :number
- Source:
- Default Value:
- 1
Type:
- number
(static) SIGILL :number
- Source:
- Default Value:
- 4
Type:
- number
(static) SIGINT :number
- Source:
- Default Value:
- 2
Type:
- number
(static) SIGIO :number
- Source:
- Default Value:
- 29
Type:
- number
(static) SIGIOT :number
- Source:
- Default Value:
- 6
Type:
- number
(static) SIGKILL :number
- Source:
- Default Value:
- 9
Type:
- number
(static) SIGPIPE :number
- Source:
- Default Value:
- 13
Type:
- number
(static) SIGPOLL :number
- Source:
- Default Value:
- 29
Type:
- number
(static) SIGPROF :number
- Source:
- Default Value:
- 27
Type:
- number
(static) SIGPWR :number
- Source:
- Default Value:
- 30
Type:
- number
(static) SIGQUIT :number
- Source:
- Default Value:
- 3
Type:
- number
(static) SIGSEGV :number
- Source:
- Default Value:
- 11
Type:
- number
(static) SIGSTKFLT :number
- Source:
- Default Value:
- 16
Type:
- number
(static) SIGSTOP :number
- Source:
- Default Value:
- 19
Type:
- number
(static) SIGSYS :number
- Source:
- Default Value:
- 31
Type:
- number
(static) SIGTERM :number
- Source:
- Default Value:
- 15
Type:
- number
(static) SIGTRAP :number
- Source:
- Default Value:
- 5
Type:
- number
(static) SIGTSTP :number
- Source:
- Default Value:
- 20
Type:
- number
(static) SIGTTIN :number
- Source:
- Default Value:
- 21
Type:
- number
(static) SIGTTOU :number
- Source:
- Default Value:
- 22
Type:
- number
(static) SIGUNUSED :number
- Source:
- Default Value:
- 31
Type:
- number
(static) SIGURG :number
- Source:
- Default Value:
- 23
Type:
- number
(static) SIGUSR1 :number
- Source:
- Default Value:
- 10
Type:
- number
(static) SIGUSR2 :number
- Source:
- Default Value:
- 12
Type:
- number
(static) SIGVTALRM :number
- Source:
- Default Value:
- 26
Type:
- number
(static) SIGWINCH :number
- Source:
- Default Value:
- 28
Type:
- number
(static) SIGXCPU :number
- Source:
- Default Value:
- 24
Type:
- number
(static) SIGXFSZ :number
- Source:
- Default Value:
- 25
Type:
- number
(static) WCONTINUED :number
- Source:
- Default Value:
- 8
Also return if a stopped child has been resumed by delivery of SIGCONT (since Linux 2.6.10)
Type:
- number
(static) WNOHANG :number
- Source:
- Default Value:
- 1
Return immediately if no child has exited
Type:
- number
(static) WUNTRACED :number
- Source:
- Default Value:
- 2
Also return if a child has stopped (but not traced via ptrace(2))
Type:
- number
Methods
(static) alarm(seconds) → {number}
- Source:
The alarm() function shall cause the system to generate a SIGALRM signal for the process after the number of realtime seconds specified by seconds have elapsed.
Processor scheduling delays may prevent the process from handling the signal as soon as it is generated.
If seconds is 0, a pending alarm request, if any, is canceled.
Alarm requests are not stacked; only one SIGALRM generation can be scheduled in this manner. If the SIGALRM signal has not yet been generated, the call shall result in rescheduling the time at which the SIGALRM signal is generated.
Parameters:
Name | Type | Description |
---|---|---|
seconds |
number |
Returns:
If there is a previous alarm() request with time remaining, alarm() shall return a non-zero value that is the number of seconds until the previous request would have generated a SIGALRM signal.
Otherwise, alarm() shall return 0.
- Type
- number
(static) atexit(inheritopt, fn) → {void}
- Source:
Register function handlers for the exit process event.
Note that, unlike the libc atexit() function, this one only invokes handlers which have been registered for the current process, and not its children.
In libc's atexit(), all handlers are inherited when a fork() is done, leading
to children process to execute atexit() handlers too. In this framework, the
default is not to inherit unless requested with inherit = true
.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
inherit |
boolean |
<optional> |
false
|
Whether to inherit the handler in forked children |
fn |
function | Handler function |
Returns:
- Type
- void
(static) chdir() → {number}
- Source:
Change process working directory.
Throws:
Returns:
0
- Type
- number
(static) exec(executable, argsopt, optsopt)
- Source:
Replace the current process image with a new process image.
Note that this function either fails or doesn't return ever because it replaces the current process image.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
executable |
string | Path or name of executable |
||
args |
Array.<string> |
<optional> |
[]
|
Array of arguments to pass to program (not including argv[0]). |
opts |
ProcExecOptions |
<optional> |
{}
|
Options for process execution. |
Throws:
(static) exit(statusopt)
- Source:
End current process returning given status code.
Note that this function doesn't return ever because it finishes the process.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
status |
number |
<optional> |
0
|
Status code to return to kernel |
(static) fork(waitopt, fnopt) → {number|ProcResult}
- Source:
This function creates a new process.
Examples
// Fork and return immediately (old school fork)
const pid = proc.fork();
if (pid === 0) {
// Run child code
...
} else {
// Run parent code
...
// Wait for child to finish
proc.waitpid(pid);
}
const pid = proc.fork(function() {
// Run child code
...
});
// Wait for child to finish
proc.waitpid(pid);
const result = proc.fork(true, function() {
// Run child code
...
});
// Check result
if (result.exit_status !== 0) {
...
}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
wait |
true |
<optional> |
Pass |
fn |
function |
<optional> |
The function that implements the child process. If not given, the method returns and the return code must be inspected to decide whether to execute parent or child code. |
Throws:
Returns:
If wait
is true
returns the result of proc.waitpid(), otherwise, the
return value is 0 in the child and the pid of the child in the parent.
- Type
- number | ProcResult
(static) fork2(getpidopt, fn) → {void|number}
- Source:
Double fork idiom used to launch detached (daemonized) processes. Note that it has builtin support to obtain the child pid if requested.
Examples
proc.fork2(function() {
// Run fire and forget daemon
...
});
const pid = proc.fork2(true, function() {
// Run managed daemon
...
});
...
// Kill daemon
proc.kill(pid);
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
getpid |
true |
<optional> |
Pass |
fn |
function | The function that implements daemon's code |
Throws:
Returns:
pid of daemon if getpid = true
- Type
- void | number
(static) getegid() → {number}
- Source:
Get the effective group id of the running process.
Returns:
A group id
- Type
- number
(static) getenv(name) → {string|null}
- Source:
Get the value of an environment variable
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The name of the environment variable |
Returns:
The value of the environment variable
- Type
- string | null
(static) geteuid() → {number}
- Source:
Get the effective user id of the running process.
Returns:
A user id
- Type
- number
(static) getgid() → {number}
- Source:
Get the group id of the running process.
Returns:
A group id
- Type
- number
(static) getpid() → {number}
- Source:
Get the pid of the running process.
Returns:
A process id
- Type
- number
(static) getppid() → {number}
- Source:
Get the pid of the parent process.
Returns:
A process id
- Type
- number
(static) getuid() → {number}
- Source:
Get the user id of the running process.
Returns:
A user id
- Type
- number
(static) kill(pid, sig) → {0}
- Source:
The kill() function can be used to send any signal to any process group or process.
For a process to have permission to send a signal, it must either be
privileged (under Linux: have the CAP_KILL capability in the user namespace
of the target process), or the real or effective user ID of the sending
process must equal the real or saved set-user-ID of the target process. In
the case of SIGCONT
, it suffices when the sending and receiving processes
belong to the same session.
Parameters:
Name | Type | Description |
---|---|---|
pid |
number | If If If If |
sig |
number | If |
Throws:
Returns:
- Type
- 0
(static) setenv(name, value, overwriteopt) → {0}
- Source:
Set an environment variable.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name |
string | Name of variable |
||
value |
string | null | Value to set or |
||
overwrite |
boolean |
<optional> |
true
|
Whether to overwrite the value if it exists |
Throws:
SysError
Returns:
- Type
- 0
(static) setsid() → {number}
- Source:
Creates a new session if the calling process is not a process group leader. The calling process is the leader of the new session (i.e., its session ID is made the same as its process ID).
The calling process also becomes the process group leader of a new process group in the session (i.e., its process group ID is made the same as its process ID).
The calling process will be the only process in the new process group and in the new session.
Initially, the new session has no controlling terminal. For details of how a session acquires a controlling terminal, see credentials(7).
Throws:
SysError
Returns:
The (new) session ID of the calling process
- Type
- number
(static) signal(sig, func) → {void}
- Source:
The signal() function chooses one of three ways in which receipt of the
signal number sig
is to be subsequently handled.
Parameters:
Name | Type | Description |
---|---|---|
sig |
number | The signal number |
func |
undefined | null | function | If the value of If the value of Otherwise, the application shall ensure that |
Throws:
SysError
Returns:
- Type
- void
(static) sleep(seconds) → {0}
- Source:
Pause execution of the running process for a given number of seconds.
Parameters:
Name | Type | Description |
---|---|---|
seconds |
number | Seconds to wait |
Throws:
SysError
Returns:
- Type
- 0
(static) unsetenv(name) → {0}
- Source:
Delete an environment variable.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | Name of environment variable |
Throws:
SysError
Returns:
- Type
- 0
(static) waitpid(pid, options) → {ProcResult}
- Source:
Parameters:
Name | Type | Description |
---|---|---|
pid |
number | < -1 meaning wait for any child process whose process group ID is equal to the absolute value of pid. -1 meaning wait for any child process. 0 meaning wait for any child process whose process group ID is equal to that of the calling process at the time of the call to waitpid(). > 0 meaning wait for the child whose process ID is equal to the value of pid. |
options |
number | Zero or an OR of proc.WNOHANG, proc.WUNTRACED, or proc.WCONTINUED. |
Throws:
SysError
Returns:
- Type
- ProcResult