fixed naming convention and text casing to use CamelCase on class fields. Process manager implemented, not tested, needs integration with current shell implementation

This commit is contained in:
2026-08-20 09:44:03 +02:00
parent 075c999435
commit 16a1805f25
5 changed files with 141 additions and 83 deletions
+54
View File
@@ -0,0 +1,54 @@
import type { CommandDescriptor } from "@core/command";
import type { ShellState } from "@core/shell_state";
import type { Signal } from "@core/signal";
import { EventEmitter } from "./event_emitter";
import { Process } from "./process";
import type { ShellEventMap } from "./shell";
export class ProcessManager {
private _Processes: Map<number, Process> = new Map();
private _PIDIndex: number = 0;
EventEmitter: EventEmitter<ShellEventMap> = new EventEmitter();
public createProcess(state: ShellState, descriptor: CommandDescriptor, flags: string[], args: string[]): void {
const pid = ++this._PIDIndex;
const process = new Process(pid, state, descriptor, flags, args);
this._Processes.set(pid, process);
process.EventEmitter.on("stdout", payload => this.EventEmitter.emit("stdout", payload));
process.EventEmitter.on("stderr", payload => this.EventEmitter.emit("stderr", payload));
process.EventEmitter.on("result", payload => {
this._Processes.delete(payload.pid);
this.EventEmitter.emit("result", payload);
});
this.EventEmitter.emit("process", { pid, name: descriptor.name });
process.execute();
}
public sendSignal(pid: number, signal: Signal): void {
const process = this._Processes.get(pid);
if (!process) {
//Implement a proper error object later to return to shell
console.error("PID not found");
return;
}
process.sendSignal(signal);
}
public kill(pid: number): void {
const process = this._Processes.get(pid);
if (!process) {
//Implement a proper error object later to return to shell
console.error("PID not found");
return;
}
//Make global signals an enum later
process.sendSignal({ type: "SIGKILL" } satisfies Signal);
}
}