Home

Awesome

lua-process

process module.

Installation

luarocks install process --from=http://mah0x211.github.io/rocks/

Constants

these constants defined at the process.*

Use for waitpid API

Environment

env = getenv()

get environment variables.

Returns

Process ID

pid = getpid()

get calling process id.

Returns

pid = getppid()

get parent process id.

Returns

Group ID

gid = getgid( [gname] )

get real group id of a calling process or a specified group-name.

Parameters

Returns

gid = getegid()

get effective group id of calling process.

Returns

gname = getgname( [gid] )

get group name of a calling process or specified group id.

Parameters

Returns

err = setgid( gid or gname )

set real group id.

Parameters

Returns

err = setegid( gid or gname )

set effective group id.

Parameters

Returns

err = setregid( rgid or gname, egid or gname )

set real and effective group id.

Parameters

Returns

User ID

uid = getuid( [uname] )

get real user id of a calling process or a specified user-name.

Parameters

Returns

uid = geteuid()

get effective user id of calling process.

Returns

uname = getuname( [uid] )

get user name of calling process or a specified user id.

Parameters

Returns

err = setuid( uid or uname )

set real user id.

Parameters

Returns

err = seteuid( uid or uname )

set effective user id.

Parameters

Returns

err = setreuid( ruid or uname, euid or uname )

set real and effective user id.

Parameters

Returns

Session ID

sid, err = getsid( pid )

get session id of the specified process.

Parameters

Returns

sid, err = setsid()

creates a new session.

Returns

Resource Utilization

usage, err = getrusage()

get information about resource utilization.

Returns

Current Working Directory

path, err = getcwd()

get working directory pathname.

Returns

err = chdir( path )

change current working directory.

Parameters

Returns

Child Process

pid, err, again = fork()

create child process.

Returns

status, err = waitpid( pid [, ...] )

wait for process termination.
please refer to man 2 waitpid for more details.

Parameters

Returns

child, err = exec( path [, args [, env [, cwd [, nonblock]]]] )

execute a specified file.

please refer to man 2 execve for more details.

Parameters

Returns

Suspend execution for an interval of time

rc = sleep( sec )

suspend execution of the calling process until specified seconds.

Parameters

Returns

rc = nsleep( nsec )

suspend execution of the calling process until specified nanoseconds.

Parameters

Returns

Errors

errno = errno()

getting current process/thread errno.

Returns

err = strerror( [errno:number] )

getting message string corresponding to errno.

Parameters

Returns

Date and Time

sec, err = gettimeofday()

get the time as well as a timezone.

Returns

Descriptors

newfd, err = dup( oldfd )

create a copy of the file descriptor oldfd.
please refer to man 2 dup for more details.

Parameters

Returns

newfd, err = dup2( oldfd, newfd )

create a copy of the file descriptor oldfd.
please refer to man 2 dup2 for more details.

Parameters

Returns

ok, err = close( fd )

close a existing file descriptor.

Parameters

Returns

Instance of process.child module

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'

pid = child:pid()

get process id.

Returns

fdin, fdout, fderr = child:fds()

get file descriptors of stdin, stdout and stderr.

Returns

data, err, again = child:stdout()

read the data from stdout of child process.

Returns

data, err, again = child:stderr()

read the data from stderr of child process.

Returns

len, err, again = child:stdin( data )

write the data to stdin of child process.

Parameters

Returns

err = child:kill( [signo] )

send signal to a child process.

Parameters

Returns