-
Notifications
You must be signed in to change notification settings - Fork 0
Process Management
The MVM (Micro Virtual Machine) kernel manages the creation, execution, and termination of processes. Processes run concurrently within the VM's emulated environment, using cooperative multitasking. The kernel uses a round-robin scheduler.
A process in the MVM can be in one of the following states:
- RUNNING: The process is currently executing instructions.
- CANCELLED: The process has terminated by another process.
- PAUSED: The process is paused by another process.
The kernel represents each process using a KProcess
object.
This object acts as the process control block (PCB), storing all essential information about the process:
-
id
: A unique integer identifier for the process. (Assigned when a process is created). -
vm
: An instance of theVm
class, representing the VM's state for this process. Each process gets its own VM object. -
file
: AFile
object, the path to the program that the process runs. -
instructionMemory
: A list ofInstructData
objects that represent the instructions in the program. -
ipcPermissions
: A list of mailbox IDs for inter-process communication (IPC) that this process has access to. -
parent
: The ID of the process's parent process (ornull
for the initial process). -
thread
: The KotlinThread
that executes instructions for the process.
This data is stored and managed by the kernel.
The kernel provides two system calls for creating processes:
-
fork()
: Creates a new process, a copy of the current process. The child process has its own memory space, registers, and stack, but it starts with the same code as the parent. returns the child process's PID to the parent process and 0 to the child process. Thethread
is determined by the VM itself. The process is initialised at runtime inKProcess.init
-
spawn(programPath.kar)
: Creates a new process under the VM using the assembly code, using the file specified byprogramPath.kar
. It will not inherit the state of the parent process. The process is added to the scheduler's ready queue.
HALT is added by the OS automatically and is inaccessible to the programmer.
A process terminates by calling the HALT
key word.
The kernel will remove the process from the scheduler's ready queue.
This is different from the exit system call which exits the entire VM, working on a fix.
Inter-process communication is managed through mailboxes.
Each process has a list of mailbox IDs (ipcPermissions
) which it has access to.
The OS manages mailboxes.
Processes communicate by sending (send
) and receiving (receive
) messages.
Processes can establish connections with other processes using the link
system call.
This document provides an overview of process management in the MVM. For detailed information about the KProcess
class
and system calls,
refer to other sections in this wiki.
Content_copy
Use code with caution.
Markdown
Built with ❤️ & Kotlin
Getting Started
Assembly Language
Standard Library
- Standard Library Overview
- String Functions
- Array Functions
- Maths Functions
- Clean Functions
- I/O Functions
- System Functions
- Conversion Functions
System Calls
- System Call Overview
- File System Calls
- Process Management Calls
- IPC Calls
- Host OS Calls
- Other System Calls
Kernel + OS
Error Handling
Advanced Topics
Appendix
Project Information