initd internals#
This document describes the inner workings of the thox process manager. See initd: process manager with thox IPC for more information regarding the concepts.
General constants#
- class initd.QUANTUM: number#
The Round Robin quantum as a number of instructions to set to
debug.sethook()
.
- class initd.YIELD#
The yield types in the process manager coroutine hijacking system.
- BASIC: number#
The basic yield, which means the process has manually called its version of the
coroutine.yield()
function. Can be returned in the process manager main loop if the process calls it from its main execution thread, and is then interpreted asYIELD.PREEMPT
.
- PREEMPT: number#
The pre-empt yield, automatically sent from the hook set by
debug.sethook()
after a fixed number of instructions if the coroutine hasn’t yielded yet.
- ANSWER: number#
The answer yield, sent when the user calls
os.answer()
.
- BIND: number#
The bind yield, sent when the user calls
os.bind()
.
- UNBIND: number#
The unbind yield, sent when the user calls
os.unbind()
.
Process Manager#
- class initd.Process#
A process as represented from the process manager’s point of view.
- thread: thread#
The thread wrapping the function to execute, produced by
coroutine.create()
.
- state: number#
The state the process currently is in, determining its treatment by the main process running loop, amongst one of the following:
- RUNNING: number#
The process is to be resumed on the next round. The code in the thread has its own environment for sandboxing purposes.
- WAITING: number#
The process is currently pulling events, which could be calls (if at least one RPC call is bound to it), answers, or events from queues the process is listening to.
- ZOMBIE: number#
The process has terminated or has been terminated, and is about to be removed.
- answer: table#
The arguments to return to the process on next resume, stored as a sequence. This is usually the answer to the last system call, or an empty table if the last yield was a pre-empt or equivalent.
It is usually composed of:
A boolean indicating the status,
true
being that the system call has been successful andfalse
signifying that an error has occurred.The payload as a table. It is composed of the
message
member if it is an error, and free-format members depending on the system call if the call has been successful.
- events: table<os.Event>#
The list of events to be sent to the function, as a sequence from which to pop events each time.
- calls: table<cid, pm.Call>#
The array of calls managed by this process.
- outgoingCount: number#
The number of outgoing calls.
- incomingCount: number#
The number of incoming calls.
- alarms: table<pm.Alarm>#
A list of alarms which the process has summoned for itself. Alarms in this array must be sorted by alarm trigger time.
- commandLine: table<string>#
The command line with which the process has been invoked. First element should contain the name or path of the script.
- resume()#
Resumes the coroutine if it is sleeping.
- class initd.Call#
A representation of a call from a process.
- type: number#
The type of the managed call, amongst the following:
- IN: number#
The call is an incoming call that awaits an answer from the current process.
- OUT: number#
The call is an outgoing call that awaits an answer from another process.
- ALARM: number#
The call is an outgoing call to the process manager to trigger an alarm after some time.
- pid: number#
The process identifier of the callee or the caller for incoming and outgoing calls.
- cid: number#
The call identifier on the other side (callee or caller, which pid is the one above) for incoming and outgoing calls.
- class initd.Alarm#
An alarm as represented in the process manager.
- cid: number#
The call identifier which created the alarm, with which to respond when the alarm is through.
- alarmAt: number#
The clock value at or after which to trigger the alarm event as an answer to the process’ call.
- class initd.ProcessManager#
The process manager object, which manages processes, sandboxing, CPU time allocations, IPC, and permissions.
- spawn(program, options)#
Spawns a process and returns its Process IDentifier (PID). The process is spawned with the running state by default.
Todo
Specify the options!
- Parameters:
program (
str
) – The program as Lua code in textual form.options (
table
) – The options for executing a process.
- kill(pid)#
Kills a process by settings its state to a zombie.
Todo
Answer unanswered calls?
- Parameters:
pid (
number
) – The PID of the process to kill.
- run()#
Run the processes until there are none left.