Module tch.posix
Bindings to POSIX functions and useful wrappers around them.
Functions
clock_elapsed(clk_id, sec[, nsec]) | Calculate the elapsed time since the given timestamp. |
clock_gettime(clk_id) | Retrieve time using the given clock ID. |
closelog() | Close the connection being used to write to the system logger. |
dup2(oldfd, newfd) | Duplicates the old file descriptor into the new file descriptor. |
execv(path[, argv]) | Replace the current process image with a new process image. |
fork() | Create a new process by duplicating the calling process. |
getpid() | Get the process ID of the calling process. |
getusername() | Get username of user running the calling process. |
inet_pton(af, src) | convert IP address to binary form |
kill(pid, sig) | Send signal to a process. |
openlog(ident, option, facility) | Open a connection to the system logger for a program. |
statvfs(path) | Retrieve statistics of the mounted file system on which the given path resides. |
sysconf(int) | Get configuration information at runtime. |
syslog(priority, msg) | Generate a log message. |
Tables
tch.posix | Constants to be used in calls to functions of this module. |
Functions
- clock_elapsed(clk_id, sec[, nsec])
-
Calculate the elapsed time since the given timestamp.
Parameters:
- clk_id
Clock ID, one of the
CLOCK_*
constants. It's your responsibility to pass the same clock ID as used to generate the initial timestamp. - sec number The number of seconds of the initial timestamp.
- nsec number The number of nanoseconds of the initial timestamp. If absent then elapsed time will be calculated based on the seconds part only. (optional)
Returns:
-
number
The number of microseconds elapsed between the initial
timestamp and now.
Raises:
Throws in case of an invalid clock ID orsec
/nsec
not being numbers.See also:
- clk_id
Clock ID, one of the
- clock_gettime(clk_id)
-
Retrieve time using the given clock ID.
Parameters:
- clk_id
Clock ID, one of the
CLOCK_*
constants.
Returns:
- number The number of seconds on the clock.
- number The number of nanoseconds on the clock.
Raises:
Throws in case of an invalid clock ID.See also:
- clk_id
Clock ID, one of the
- closelog()
-
Close the connection being used to write to the system logger.
See also:
- dup2(oldfd, newfd)
-
Duplicates the old file descriptor into the new file descriptor.
The new file descriptor is closed first if necessary.
Parameters:
- oldfd int The file descriptor to duplicate.
- newfd int The file descriptor to duplicate to.
Returns:
-
int
The new file descriptor.
Or
- nil
- string Error message.
See also:
- execv(path[, argv])
-
Replace the current process image with a new process image.
This function only returns if an error occurred.
Parameters:
- path string The file to be executed.
- argv {string,...} Array with the arguments to provide to the new program. (optional)
Returns:
- nil
- string Error message.
See also:
- fork()
-
Create a new process by duplicating the calling process.
Returns:
-
number
The PID of the child process is returned in the parent, and
0 is returned in the child.
Or
- nil
- string Error message.
See also:
- getpid()
-
Get the process ID of the calling process.
Returns:
-
number
The process ID of the calling process.
See also:
- getusername()
-
Get username of user running the calling process.
Returns:
-
string
The username of the user running the calling process.
Or
- nil
- string Error message.
See also:
- inet_pton(af, src)
-
convert IP address to binary form
Parameters:
- af
int
The address family, either
AF_INET
orAF_INET6
. - src string The IP address string to convert.
Returns:
-
string
The binary representation of the given address.
Or
- nil
- string Error message.
See also:
- af
int
The address family, either
- kill(pid, sig)
-
Send signal to a process.
Parameters:
- pid int The process ID of the process to send signal to.
- sig
int
The signal to send to process:
SIGTERM
,SIGKILL
or '0' to check if process exists.
Returns:
-
number
The return value of
kill()
or nil otherwise.Or
- nil
- string Error message.
See also:
- openlog(ident, option, facility)
-
Open a connection to the system logger for a program.
Parameters:
- ident string Represent the program name.
- option
int
Bitwise OR of the applicable
LOG_*
constants to control the operation of this function and subsequent calls to syslog. - facility
int
One of the applicable
LOG_*
constants which will be the default facility when none is specified in subsequent calls to syslog.
See also:
- statvfs(path)
-
Retrieve statistics of the mounted file system on which the given path resides.
Parameters:
- path string A pathname whose underlying filesystem the statistics will be retrieved from.
Returns:
-
table
All the fields of the
struct statvfs
are the keys; the values are numbers.Raises:
Throws in case of an invalid path.See also:
- sysconf(int)
-
Get configuration information at runtime.
Parameters:
- int
Any valid sysconf value is accepted but only
_SC_CLK_TCK
is exported by the module.
Returns:
-
int
Associated system configuration value.
See also:
- int
Any valid sysconf value is accepted but only
- syslog(priority, msg)
-
Generate a log message.
Parameters:
- priority
int
Bitwise OR of relevant facility and level
LOG_*
constants. - msg string The message to log.
See also:
- priority
int
Bitwise OR of relevant facility and level
Tables
- tch.posix
-
Constants to be used in calls to functions of this module.
Fields:
- CLOCK_REALTIME Realtime clock ID for use in clock_gettime and clock_elapsed.
- CLOCK_MONOTONIC Monotonic clock ID for use in clock_gettime and clock_elapsed.
- ST_RDONLY
Bit in the
f_flag
field of the table returned by statvfs indicating a read-only filesystem. - ST_NOSUID
Bit in the
f_flag
field of the table returned by statvfs indicating set-user-ID and set-group-ID bits are ignored by exec(3). - SIGKILL Using kill, send signal '9' to process. This is equivalent to shell command 'kill -9'.
- SIGTERM
Using kill, send signal '15' to process. This is equivalent to shell command kill, since
SIGTERM
is the default signal. - AF_INET IPv4 address family.
- AF_INET6
IPv6 address family.
Constants to be used for the
option
argument to openlog. - LOG_CONS Write directly to system console if there is an error while sending to system logger.
- LOG_NDELAY Open the connection immediately (normally, the connection is opened when the first message is logged).
- LOG_NOWAIT Don't wait for child processes that may have been created while logging the message.
- LOG_ODELAY
The converse of
LOG_NDELAY
; opening of the connection is delayed until syslog() is called. - LOG_PERROR Print to stderr as well.
- LOG_PID
Include PID with each message.
Constants to be used to specify the facility in openlog and syslog.
- LOG_AUTH security/authorization messages
- LOG_AUTHPRIV security/authorization messages
- LOG_CRON clock daemon
- LOG_DAEMON system daemons without separate facility value
- LOG_FTP ftp daemon
- LOG_LOCAL0
through
LOG_LOCAL7
reserved for local use - LOG_LPR line printer subsystem
- LOG_MAIL mail subsystem
- LOG_NEWS USENET news subsystem
- LOG_SYSLOG messages generated internally by syslogd()
- LOG_USER (default) generic user-level messages
- LOG_UUCP
UUCP subsystem
Constants to be used to specify the log level in \syslog
.
- LOG_EMERG system is unusable
- LOG_ALERT action must be taken immediately
- LOG_CRIT critical conditions
- LOG_ERR error conditions
- LOG_WARNING warning conditions
- LOG_NOTICE normal, but significant, condition
- LOG_INFO informational message
- LOG_DEBUG debug-level message