File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed
Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change 77use Laminas \Diagnostics \Result \ResultInterface ;
88use Laminas \Diagnostics \Result \Success ;
99
10- use function escapeshellarg ;
1110use function exec ;
1211use function gettype ;
1312use function is_numeric ;
1413use function is_scalar ;
1514use function sprintf ;
15+ use function str_contains ;
1616
1717/**
1818 * Check if a process with given name or ID is currently running.
@@ -94,12 +94,23 @@ private function checkAgainstPid()
9494 */
9595 private function checkAgainstProcessName ()
9696 {
97- exec ('ps -efww | grep ' . escapeshellarg ($ this ->processName ) . ' | grep -v grep ' , $ output , $ return );
97+ /**
98+ * @see https://man7.org/linux/man-pages/ps.1.html (search for 'ps -eo') for GNU implementation
99+ * @see https://busybox.net/downloads/BusyBox.html (search for 'ps') for BusyBox implementation
100+ */
101+ exec ('ps -eo pid,args ' , $ output , $ return );
98102
99103 if ($ return > 0 ) {
100104 return new Failure (sprintf ('Could not find any running process containing "%s" ' , $ this ->processName ));
101105 }
102106
103- return new Success ();
107+ /** @var string $line */
108+ foreach ($ output as $ line ) {
109+ if (str_contains ($ line , $ this ->processName )) {
110+ return new Success ();
111+ }
112+ }
113+
114+ return new Failure (sprintf ('Could not find any running process containing "%s" ' , $ this ->processName ));
104115 }
105116}
You can’t perform that action at this time.
0 commit comments