Process Handler
ArcOS has a sophisticated kernel module for handling processes: the ProcessHandler. This module handles the spawning and killing of processes. To render an application, it uses the AppRenderer, a process that's spawned before the ArcOS boot screen appears.
Spawning a process
To spawn another application, use the AppProcess.spawnApp
or AppProcess.spawnOverlayApp
functions, which are part of every app process:
spawnApp<T = AppProcess>(id: string, parentPid?: number | undefined, ...args: any[]): Promise<T | undefined>;
spawnOverlayApp<T = AppProcess>(id: string, parentPid?: number | undefined, ...args: any[]): Promise<T | undefined>;
For example, to open a file in the Writer app with the current process as the parent, you'd call spawnApp
as such:
const path = "U:/Documents/test.txt";
const process = await this.spawnApp("writer", this.pid, path);
If successful, the functions return the process that was just created. To see what these processes contain, consult the Process
and AppProcess
classes in the arcos.d.ts
file, located in the root of your project.
Killing a process
To kill a process, use ProcessHandler.kill
. This function terminates the process and its children. Here's the syntax:
kill(pid: number, force?: boolean): Promise<ProcessKillResult>;
ProcessKillResult
can be any one of these strings:
success
The process was killed successfully.
err_elevation
Elevation is required, but wasn't provided
err_criticalProcess
The process is required for ArcOS to run properly.
err_disposed
The process is already killed
err_noExist
The process doesn't exist
err_killCancel
The process didn't permit the kill. It might still have pending operations.
Getting a process
If you need to get a process instance, use the ProcessHandler.getProcess
method. It takes a PID and returns the process if it can be found:
getProcess<T = Process>(pid: number, disposedToo?: boolean): T | undefined;
disposedToo
decides if the method can return a process that has already been killed. Disposed processes remain on the stack with their _disposed
property set to true
.
Last updated