POSIX support library


pposix.daemonize() forks the process to the background.

Also closes stdin, stdout and stderr and opens /dev/null three times to prevent accidentally reusing the first three file descriptors.


For logging to syslog.

Function Description
syslog_open(name, facility) Connect to syslog
syslog_log(level, [section,] message) Send a message to syslog
syslog_setminlevel(level) Set minimum log level
syslog_close() Close syslog connection

process/user id

Return or set some numbers associated with a process. These are thin wrappers around POSIX / C funcitions of the same names.

Function Description
getpid() Get process id.
getuid() Get user id.
getgid() Get group id
setuid(uid) Change to a different user (must be root)
setgid(uid) Change to a different group (must be root)
initgroups(?) Initialize additional groups when changing user

facility are strings such as auth, daemon, mail etc to be used by the syslog deamon for routing to the correct log file.

level is one of debug, info, notice, warn, error.


Set umask, which determines what permissions newly created files get.


Create a directory.


getrlimit, setrlimit

Get or modify limits applied to the calling process, similar to the userspace ulimit tool. Each "resource" have two different limits, one "soft" or active limit and one "hard" limit. The "hard" limit determines the maximum value that the application can set the limit to, and as such can only be decreased.

pposix.getlimit(resource) if successful returns a boolean true and two numbers. The first being the current "soft" limit for the resource queried, the second being the "hard" maximum that the limit can be increased to.

pposix.setrlimit(resource, limit, hard_limit) attempts to change the "soft" and "hard" limits to the value given as second and third argument.


Returns a table with information about the kernel and machine, similar to the userspace uname tool.



pposix.setenv(name, value) sets environment variables. Lua itself provides os.getenv(name) for reading.


pposix.meminfo() returns a table with information from the memory allocator malloc.

field description
allocated This is the total size of memory allocated with sbrk by malloc, in bytes.
allocated_mmap This is the total size of memory allocated with mmap, in bytes.
used This is the total size of memory occupied by chunks handed out by malloc.
unused This is the total size of memory occupied by free (not in use) chunks.
returnable This is the size of the top-most releasable chunk that normally borders the end of the heap.


pposix.fallocate(file, offset, length) requests that some space on the disk is allocated to a file handle. If fallocate() succeeds, a subsequent write of at most length bytes to the file should not fail.


Cause an abnormal program termination with core-dump.