process module.
luarocks install process --from=http://mah0x211.github.io/rocks/
these constants defined at the process.*
Use for waitpid
API
WNOHANG
WUNTRACED
WCONTINUED
WNOWAIT
get environment variables.
Returns
env:table
: environment variables.
get calling process id.
Returns
pid:number
: process id.
get parent process id.
Returns
pid:number
: parent process id.
get real group id of a calling process or a specified group-name.
Parameters
gname:string
: group name.
Returns
gid:number
: group id.
get effective group id of calling process.
Returns
gid:number
: group id.
get group name of a calling process or specified group id.
Parameters
gid:number
: group id.
Returns
gname:string
: group name.
set real group id.
Parameters
gid:number
: group id.gname:string
: group name.
Returns
err:string
: nil on succes, or error string on failure.
set effective group id.
Parameters
gid:number
: group id.gname:string
: group name.
Returns
err:string
: nil on succes, or error string on failure.
set real and effective group id.
Parameters
rgid:number
: real group id.egid:number
: effective group id.gname:string
: group name.
Returns
err:string
: nil on succes, or error string on failure.
get real user id of a calling process or a specified user-name.
Parameters
uname:string
: user name.
Returns
uid:number
: user id.
get effective user id of calling process.
Returns
uid:number
: user id.
get user name of calling process or a specified user id.
Parameters
uid:number
: user id.
Returns
uname:string
: user name.
set real user id.
Parameters
uid:number
: user id.uname:string
: user name.
Returns
err:string
: nil on succes, or error string on failure.
set effective user id.
Parameters
uid:number
: user id.uname:string
: user name.
Returns
err:string
: nil on succes, or error string on failure.
set real and effective user id.
Parameters
ruid:number
: real user id.euid:number
: effective user id.uname:string
: user name.
Returns
err:string
: nil on succes, or error string on failure.
get session id of the specified process.
Parameters
pid:number
: process id.
Returns
sid:number
: session id.err:string
: nil on succes, or error string on failure.
creates a new session.
Returns
sid:number
: session id.err:string
: nil on succes, or error string on failure.
get information about resource utilization.
Returns
usage:table
: table ofstruct rusage
.err:string
: nil on success, or error string on failure.
get working directory pathname.
Returns
path:string
: working directory pathname.err:string
: nil on success, or error string on failure
change current working directory.
Parameters
path:string
: valid directory path string.
Returns
err:string
: nil on success, or error string on failure.
create child process.
Returns
pid:number
: 0 to the child process, and a child process id to the calling process on success, or nil on failure.err:string
: nil on success, or error string on failure.again:boolean
: true if got EAGAIN.
wait for process termination.
please refer to man 2 waitpid
for more details.
Parameters
pid:number
: process id (default:-1
)....
: to use the following options;WNOHANG
WUNTRACED
WCONTINUED
WNOWAIT
Returns
status:table
: status table if succeeded.pid
=pid:number
.exit
=exit_status:number
ifWIFEXITED
is true.termsig
=signo:number
ifWIFSIGNALED
is true.stopsig
=signo:number
ifWIFSIGNALED
is true.continue
=true
ifWIFCONTINUED
is truenochild
=true
iferrno
isECHILD
.
err:string
: nil on success, or error string on failure.
execute a specified file.
please refer to man 2 execve
for more details.
Parameters
path:string
: filepath.args:table
: argument array table.env:table
: argument key-value pair table.cwd:string
: custom working directory.nonblock:boolean
: if set to true,child:stdin
,child:stdout
andchild:stderr
are in non-blocking mode.
Returns
child:process.child
: instantance ofprocess.child
module.err:string
: nil on success, or error string on failure.
suspend execution of the calling process until specified seconds.
Parameters
sec:number
: unsigned integer number.
Returns
rc:number
: 0 on success, and >0 if an error occurs.
suspend execution of the calling process until specified nanoseconds.
Parameters
nsec:number
: unsigned integer.
Returns
rc:number
: 0 on success, and >0 if an error occurs.
getting current process/thread errno.
Returns
errno:number
: current process/thread errno.
getting message string corresponding to errno.
Parameters
errno:number
: error number that defined inerrno.h
.
if passed argument is nil then to use global errno.
Returns
err:string
: error string.
get the time as well as a timezone.
Returns
sec:number
: current time.err:string
: nil on success, or error string on failure.
create a copy of the file descriptor oldfd.
please refer to man 2 dup
for more details.
Parameters
oldfd:number
: file descriptor.
Returns
newfd:number
: new file descriptor.err:string
: nil on success, or error string on failure.
create a copy of the file descriptor oldfd.
please refer to man 2 dup2
for more details.
Parameters
oldfd:number
: file descriptor.newfd:number
: file descriptor.
Returns
newfd:number
: new file descriptor.err:string
: nil on success, or error string on failure.
close a existing file descriptor.
Parameters
fd:number
: file descriptor.
Returns
ok:boolean
: true on success, or false on failure.err:string
: error string on failure.
process.exec
API return this instance on success.
Example
local exec = require('process').exec;
local cmd = exec( 'echo', { 'hello world' } );
-- read from stdout
print( cmd:stdout() ); -- 'hello world\n'
get process id.
Returns
pid:number
: process id.
get file descriptors of stdin, stdout and stderr.
Returns
fdin:number
: stdin file descriptor.fdout:number
: stdout file descriptor.fderr:number
: stderr file descriptor.
read the data from stdout of child process.
Returns
data:string
: data as string.err:string
: nil on success, or error string on failure.again:boolean
: true if got aEAGAIN
orEWOULDBLOCK
.
read the data from stderr of child process.
Returns
data:string
: data as string.err:string
: nil on success, or error string on failure.again:boolean
: true if got aEAGAIN
orEWOULDBLOCK
.
write the data to stdin of child process.
Parameters
data:string
: data string.
Returns
len:number
: number of bytes written.err:string
: nil on success, or error string on failure.again:boolean
: true if got aEAGAIN
orEWOULDBLOCK
.
send signal to a child process.
Parameters
signo:number
: signal number. defaultSIGTERM
.
Returns
err:string
: nil on success, or error string on failure.