Created
October 4, 2017 12:46
-
-
Save bulton-fr/74916c1905eb6ed4d104086445cc6a73 to your computer and use it in GitHub Desktop.
Search and get all runned process with a name filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$exec = shell_exec('ps ax|grep myProcessName'); | |
$execList = explode("\n", $exec); | |
$processList = []; | |
foreach ($execList as $processLine) { | |
$matches = []; | |
if (preg_match('/(\d+) (.*) (S.*) (\d+:\d+) (.*)/', $processLine, $matches) === false) { | |
continue; | |
} | |
if (!isset($matches[1])) { | |
continue; | |
} | |
// PID TTY STAT TIME COMMAND | |
$processInfos = (object) [ | |
'pid' => trim($matches[1]), | |
'tty' => trim($matches[2]), | |
'stat' => trim($matches[3]), | |
'time' => trim($matches[4]), | |
'cmd' => trim($matches[5]) | |
]; | |
if ($processInfos->cmd !== '') { | |
$processList[] = $processInfos; | |
} | |
} | |
var_dump($processList); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment