diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:44:51 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:44:51 +0000 |
commit | a1ec78bf0dc93d0e05e5f066f1949dc3baecea06 (patch) | |
tree | ee596ce1bc9840661386f96f9b8d1f919a106317 /vendor/gipfl/process/src/ProcessInfo.php | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-incubator-a1ec78bf0dc93d0e05e5f066f1949dc3baecea06.tar.xz icingaweb2-module-incubator-a1ec78bf0dc93d0e05e5f066f1949dc3baecea06.zip |
Adding upstream version 0.20.0.upstream/0.20.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gipfl/process/src/ProcessInfo.php')
-rw-r--r-- | vendor/gipfl/process/src/ProcessInfo.php | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/vendor/gipfl/process/src/ProcessInfo.php b/vendor/gipfl/process/src/ProcessInfo.php new file mode 100644 index 0000000..db740d1 --- /dev/null +++ b/vendor/gipfl/process/src/ProcessInfo.php @@ -0,0 +1,89 @@ +<?php + +namespace gipfl\Process; + +use gipfl\Json\JsonSerialization; +use gipfl\LinuxHealth\Memory; +use React\ChildProcess\Process; + +class ProcessInfo implements JsonSerialization +{ + /** @var ?int */ + protected $pid; + + /** @var string */ + protected $command; + + /** @var bool */ + protected $running; + + /** @var ?object */ + protected $memory; + + public static function forProcess(Process $process) + { + $self = new static(); + $self->pid = $process->getPid(); + $self->command = $process->getCommand(); + $self->running = $process->isRunning(); + if ($memory = Memory::getUsageForPid($self->pid)) { + $self->memory = $memory; + } + + return $self; + } + + public static function fromSerialization($any) + { + $self = new static(); + $self->pid = $any->pid; + $self->command = $any->command; + $self->running = $any->running; + $self->memory = $any->memory; + + return $self; + } + + /** + * @return int|null + */ + public function getPid() + { + return $this->pid; + } + + /** + * @return string + */ + public function getCommand() + { + return $this->command; + } + + /** + * @return bool + */ + public function isRunning() + { + return $this->running; + } + + /** + * @return object|null + */ + public function getMemory() + { + return $this->memory; + } + + #[\ReturnTypeWillChange] + public function jsonSerialize() + { + return (object) [ + 'pid' => $this->pid, + 'command' => $this->command, + 'running' => $this->running, + 'memory' => $this->memory, + ]; + } +} |