Module system.ipc

The IPC module provides functions for sending messages to other processes.

Index

Data

signal

Constants for signal numbers

Function

kill()

Sends a basic signal to a process.

lookup()

Returns the ID of the process that receives a service name.

receiveEvent()

Waits for a remote event, filtering for processes or event names, with an optional timeout.

register()

Registers the current process as the receiver of a service name.

sendEvent()

Sends a remote event to a process.

sendServiceEvent()

Sends an event to the owner of a service.

sigaction()

Sets the handler for a signal.

Class

socket

Sockets are based on top of the remote event subsystem, sending messages through specially named events.

API Reference

system.ipc.signal: table

Constants for signal numbers

system.ipc.kill(pid: number, signal: number): unknown

Sends a basic signal to a process.

Parameters:
  • pid (number) – The PID of the process to send to

  • signal (number) – The signal to send to the process

system.ipc.sigaction(signal: number, fn: function | nil): unknown

Sets the handler for a signal.

Parameters:
  • signal (number) – The signal to modify

  • fn (function | nil) – The function to call, or nil to remove

system.ipc.sendEvent(pid: number, event: string, param: table): (result: boolean)

Sends a remote event to a process.

Parameters:
  • pid (number) – The PID of the process to send to

  • event (string) – The event name to send

  • param (table) – The parameter table to send with the event

Returns:

result (boolean) – Whether the event was sent

system.ipc.register(name: string): (result: boolean)

Registers the current process as the receiver of a service name.

See :lua:obj:lookup: To find a process for a service

Parameters:

name (string) – The service name to register for

Returns:

result (boolean) – Whether the service was registered

system.ipc.lookup(name: string): (result: number | nil)

Returns the ID of the process that receives a service name.

See :lua:obj:register: To register your process for a service

Parameters:

name (string) – The service to lookup

Returns:

result (number | nil) – The PID of the process that owns it (if available)

system.ipc.sendServiceEvent(name: string, event: string, param: table): (result: boolean)

Sends an event to the owner of a service.

Parameters:
  • name (string) – The service to send to

  • event (string) – The event name to send

  • param (table) – The parameter table to send with the event

Returns:

result (boolean) – Whether the event was sent

system.ipc.receiveEvent(pid?: number, event?: string, timeout?: number): (event: string | nil, param: table | nil)

Waits for a remote event, filtering for processes or event names, with an optional timeout.

Parameters:
  • pid? (number) – The PID to wait for an event from

  • event? (string) – The event to filter for

  • timeout? (number) – The maximum number of seconds to wait for

Returns:
  • event (string | nil) – The event name received, or nil if the timer timed out

  • param (table | nil) – The parameters for the event

class system.ipc.socket

Sockets are based on top of the remote event subsystem, sending messages through specially named events.

They implement the network handle interface and as such can be used instead of a network handle (though note that these sockets have no buffer and as such should not be used for continuous streams of data, as a network handle often is used for). Sockets will only receive messages from the same sender PID and socket name, so they can be isolated from other sockets.

status(self: system.ipc.socket): string
close(self: system.ipc.socket)
closed: boolean
read(self: system.ipc.socket, fmt: any, ...: unknown): string | number, string | number | nil, string | number | nil
write(self: system.ipc.socket, obj: any, ...: unknown): unknown