ProcessVisor class
A process supervisor that can start, stop, restart, and monitor an OS process.
ProcessVisor manages the lifecycle of a single process, providing:
- Process spawning with configurable working directory and environment
- Stream handling for stdout/stderr output via LogWriter callbacks
- Automatic restart on process failure (configurable)
- Graceful shutdown with fallback to force kill
- Optional startup readiness detection via StartIndicator
Example usage:
final visor = ProcessVisor(
args: ['ping', '127.0.0.1'],
logWriter: (record) => print('${record.pid}: ${record.text}'),
restartOnFailure: true,
startIndicator: (record) => record.text.contains('64 bytes'),
);
await visor.start();
// Process runs and logs output...
await visor.stop();
visor.close(); // Clean up resources
Constructors
-
ProcessVisor({required List<
String> args, String? workingDirectory, Map<String, String> ? environment, bool restartOnFailure = false, required LogWriter logWriter, StartIndicator? startIndicator}) - Creates a new ProcessVisor to manage a process.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- pid → int?
-
The process ID (PID) of the currently running or last ran process.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
started
→ Future<
void> -
A future that completes when the process reaches its first running status.
no setter
- status → ProcessStatus
-
The current status of the managed process.
no setter
-
statusChanges
→ Stream<
ProcessStatus> -
A stream of status changes for the managed process.
no setter
Methods
-
close(
) → void - Closes the ProcessVisor and releases all resources.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
restart(
) → Future< void> - Restarts the managed process by stopping it and starting it again.
-
start(
) → Future< void> - Starts the managed process.
-
stop(
{bool force = false}) → Future< void> - Stops the managed process gracefully.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited