Class luci.sys.process

LuCI system utilities / process related functions.

Functions

exec (commend, stdout, stderr, nowait) Execute a process, optionally capturing stdio.
info () Get the current process id.
list () Retrieve information about currently running processes.
setgroup (gid) Set the gid of a process identified by given pid.
setuser (uid) Set the uid of a process identified by given pid.
signal (pid, sig) Send a signal to a process identified by given pid.


Functions

exec (commend, stdout, stderr, nowait)
Execute a process, optionally capturing stdio. Executes the process specified by the given argv vector, e.g. { "/bin/sh", "-c", "echo 1" } and waits for it to terminate unless a true value has been passed for the "nowait" parameter. When a function value is passed for the stdout or stderr arguments, the passed function is repeatedly called for each chunk read from the corresponding stdio stream. The read data is passed as string containing at most 4096 bytes at a time. When a true, non-function value is passed for the stdout or stderr arguments, the data of the corresponding stdio stream is read into an internal string buffer and returned as "stdout" or "stderr" field respectively in the result table. When a true value is passed to the nowait parameter, the function does not await process termination but returns as soon as all captured stdio streams have been closed or - if no streams are captured - immediately after launching the process.

Parameters

  • commend: Table containing the argv vector to execute
  • stdout: Callback function or boolean to indicate capturing (optional)
  • stderr: Callback function or boolean to indicate capturing (optional)
  • nowait: Don't wait for process termination when true (optional)

Return value:

Table containing at least the fields "code" which holds the exit status of the invoked process or "-1" on error and "pid", which contains the process id assigned to the spawned process. When stdout and/or stderr capturing has been requested, it additionally contains "stdout" and "stderr" fields respectively, holding the captured stdio data as string.
info ()
Get the current process id.

Return value:

Number containing the current pid
list ()
Retrieve information about currently running processes.

Return value:

Table containing process information
setgroup (gid)
Set the gid of a process identified by given pid.

Parameters

  • gid: Number containing the Unix group id

Return values:

  1. Boolean indicating successful operation
  2. String containing the error message if failed
  3. Number containing the error code if failed
setuser (uid)
Set the uid of a process identified by given pid.

Parameters

  • uid: Number containing the Unix user id

Return values:

  1. Boolean indicating successful operation
  2. String containing the error message if failed
  3. Number containing the error code if failed
signal (pid, sig)
Send a signal to a process identified by given pid.

Parameters

  • pid: Number containing the process id
  • sig: Signal to send (default: 15 [SIGTERM])

Return values:

  1. Boolean indicating successful operation
  2. Number containing the error code if failed

Valid XHTML 1.0!