跳到主要内容

进程

Class: Process

提供进程管理功能的类。

静态方法

exec

static exec(command: string, args: string[]): Promise<Process>

执行命令并返回一个 Process 实例。

  • 参数:
    • command: 要执行的命令
    • args: 命令参数数组
  • 返回: Promise<Process>

kill

static kill(id: string): Promise<boolean>

通过 ID 终止进程。

  • 参数:
    • id: 进程 ID
  • 返回: Promise<boolean>

list

static list(): Promise<ProcessInfo[]>

列出所有运行中的进程。

  • 返回: Promise<ProcessInfo[]>

info

static info(id: string): Promise<ProcessInfo>

获取特定进程的信息。

  • 参数:
    • id: 进程 ID
  • 返回: Promise<ProcessInfo>

实例方法

id

get id(): string

获取进程 ID。

  • 返回: string

kill

kill(): Promise<boolean>

终止当前进程。

  • 返回: Promise<boolean>

info

info(): Promise<ProcessInfo>

获取当前进程的信息。

  • 返回: Promise<ProcessInfo>

logEvents

logEvents(): LogEventWatcher

获取进程的日志事件监视器。

  • 返回: LogEventWatcher

Class: LogEventWatcher

用于处理进程日志事件的类,继承自 EventWatcher。

方法

close

close(): void

关闭日志事件监视器。

枚举

ProcessStatus

enum ProcessStatus {
Running = "running",
Killed = "killed",
Exited = "exited"
}

ProcessEvent

enum ProcessEvent {
Running = "processRunning",
Killed = "processKilled",
Exited = "processExited"
}

LogEvent

enum LogEvent {
Data = "data",
End = "end",
Out = "out",
Error = "error"
}

接口

ProcessInfo

interface ProcessInfo {
id: string;
status: ProcessStatus;
memory: number;
}