builtin/processModule

Synopsis

SilkJS builtin process object.

Description

The builtin/process object provides constants and methods to directly access the underlying operating system's process-oriented functions.

Usage

var process = require('builtin/process');

See Also

Operating system man pages

Function: process.error

Synopsis

Returns string version of last OS error.

Usage:

var message = process.error();

Returns

  • {string} message - error message.

Back to top


Function: process.getuid

Synopsis

Returns real user ID (uid) of calling process

Usage:

var uid = process.getuid();

Returns

  • {int} uid - real user ID

Back to top


Function: process.setuid

Synopsis

Set real user ID (uid) of calling process

Usage:

var status = process.getuid(newId);

Arguments

  • {int} newId - user ID to set for calling process

Returns

  • {int} status - 0 if successful, -1 if not (call process.error for details)

Back to top


Function: process.getgid

Synopsis

Returns real group ID (gid) of calling process

Usage:

var gid = process.getgid();

Returns

  • {int} gid - real group ID

Back to top


Function: process.setgid

Synopsis

Set real group ID (gid) of calling process

Usage:

var status = process.getgid(newId);

Arguments

  • {int} newId - group ID to set for calling process

Returns

  • {int} status - 0 if successful, -1 if not (call process.error for details)

Back to top


Function: process.getpwnam

Synopsis

Get user information from the system user database

Usage:

var info = process.getpwnam(login);

Info Structure

The returned object has the following fields:
name: login name
passwd: the user's password (may not be reliable if using shadow, etc.)
uid: the user's user ID
gid: the user's group ID
gecos: "user information"
dir: user's home directory
shell: user's shell

Arguments

  • {string} login - login name of user to get info for

Returns

  • {int} info - object as described above (Info Structure)

Back to top


Function: process.getpwuid

Synopsis

Get user information from the system user database

Usage:

var info = process.getpwnam(uid);

Info Structure

The returned object has the following fields:
name: login name
passwd: the user's password (may not be reliable if using shadow, etc.)
uid: the user's user ID
gid: the user's group ID
gecos: "user information"
dir: user's home directory
shell: user's shell

Arguments

  • {int} uid - user Id of user to get info for

Returns

  • {int} info - object as described above (Info Structure)

Back to top


Function: process.getgrnam

Synopsis

Get group information from the system user database

Usage:

var info = process.getgrnam(name);

Info Structure

The returned object has the following fields:
name: group name
passwd: the group's password (may not be reliable if using shadow, etc.)
gid: the user's group ID
mem: array of member names (strings)

Arguments

  • {string} name - name of group to get info for

Returns

  • {int} info - object as described above (Info Structure)

Back to top


Function: process.getgruid

Synopsis

Get group information from the system user database

Usage:

var info = process.getgrgid(gid);

Info Structure

The returned object has the following fields:
name: group name
passwd: the group's password (may not be reliable if using shadow, etc.)
gid: the user's group ID
mem: array of member names (strings)

Arguments

  • {int} gid - group ID of group to get info for

Returns

  • {int} info - object as described above (Info Structure)

Back to top


Function: process.kill

Synopsis

var success = process.kill(pid);

Send the SIGKILL signal to the specified process (by pid).

Arguments

  • {int} pid - process ID (pid) of process to kill.

Returns

  • {int} success - 0 on success, 1 if an error occurred.

Back to top


Function: process.getpid

Synopsis

var my_pid = process.getpid();

Returns the pid of the current process.

Returns

  • {int} my_pid - process ID (pid) of the current process.

Back to top


Function: process.fork

Synopsis

var pid = process.fork();

Create a new process.

Description

Fork() causes creation of a new process. The new process (child process) is an exact copy of the calling process (parent process) except for the following:

  1. The child process has a unique process ID.

  2. The child process has a different parent process ID (i.e., the process ID of the parent process).

  3. The child process has its own copy of the parent's descriptors. These descriptors reference the same underlying objects, so that, for instance, file pointers in file objects are shared between the child and the parent, so that an lseek(2) on a descriptor in the child process can affect a subsequent read or write by the parent. This descriptor copying is also used by the shell to establish standard input and output for newly created processes as well as to set up pipes.

  4. The child processes resource utilizations are set to 0; see the man page for setrlimit(2).

Returns

  • 0 to the child, the pid of the created process to the parent. If an error occurred, -1 is returned.

Back to top


Function: process.exit

Synopsis

process.exit(status);

Terminate the current process or program, returning status to the parent or shell.

Arguments

  • {int} status - status code to return to parent or shell.

Returns

  • NEVER

Back to top


Function: process.sleep

Synopsis

process.sleep(seconds);

Suspend execution of the current process for specified number of seconds.

Arguments

  • {int} seconds - number of seconds to suspend.

Back to top


Function: process.usleep

Synopsis

process.usleep(microseconds);

Suspend execution of the current process for specified number of microseconds.

Arguments

  • {int} microseconds - number of microseconds to suspend.

Back to top


Function: process.wait

Synopsis

var o = process.wait();
var o = process.wait(poll)

Wait for process termination.

Description

This function suspends execution of its calling process until one of its child processes terminates. The function returns an object of the form:

  • pid: the pid of the child process that terminated
  • status: the status returned by the child process

Arguments

  • {boolean} poll - if true, then this function will return immediately whether a child process has exited or not.

Returns

  • {object} o - information about the process that terminated. If polling and no process exited, false is returned.

See Also

process.exit()

Back to top


Function: process.exec

Synopsis

var output = process.exec(command_line);

Execute a Unix command, returning the output of the command (it's stdout) as a JavaScript string.

Description

This function calls popen() with the specified command line and reads its output until end of file. Under the hood, a fork() and exec() is performed which is not particularly fast. Still it can be useful to execute shell commands.

Arguments

  • {string} command_line - a Unix command to execute

Returns

  • {string} output - the output of the command executed.

Back to top


Function: process.exec_result();

Synopsis

var result = process.exec_result);

Returns the exit code of the last process.exec() call.

NOTE: The value is the low-order 8 bits of the argument the program run by exec() passed to _exit(2) or exit(3).

Returns

  • {int} result - exit code

Back to top


Function: process.env

Synopsis

var env = process.env();

Get a hash of key/value pairs representing the environment of the calling process.

Typical kinds of environment variables you'll see returned by this function are:
HOME - user's home directory.
PATH - the sequence of directories, separated by colons, searched for command execution.
...

Returns

  • {object} env - hash of key/value environment variables.

Back to top


Function: process.rusage

Synopsis

var o = process.rusage();

Get resource usage information for current process.

The object returned is of the form:

  • time: total user + system CPU time used.
  • utime: user CPU time used (float, in seconds).
  • stime: system CPU time used (float, in seconds).
  • maxrss: maximum resident set size.
  • ixrss: integral shared memory size.
  • idrss: integral unshared data size.
  • isrss: integral unshared stack size.
  • minflt: page reclaimes (soft page faults).
  • majflt: page faults (hard page faults).
  • nswap: swaps.
  • inblock: block input operations.
  • oublock: block output operations.
  • msgsnd: IPC messages sent.
  • msgrcv: IPC messages received.
  • nsignals: signals received.
  • nvcsw: voluntary context switches.
  • nivcsw: involuntary context switches.

Back to top


Function: process.getlogin

Synopsis

var username = process.getlogin();

Get a string containing the name of the user logged in on the controlling terminal of the process.

Returns

  • {string} username - name of user or false if error.

Back to top


blog comments powered by Disqus