2015-04-09 08:51:45 +02:00
|
|
|
<?php
|
|
|
|
|
2016-07-19 20:28:11 +02:00
|
|
|
namespace PHPCensor\ProcessControl;
|
2015-04-09 08:51:45 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Control process using the POSIX extension.
|
|
|
|
*
|
|
|
|
* @author Adirelle <adirelle@gmail.com>
|
|
|
|
*/
|
|
|
|
class PosixProcessControl implements ProcessControlInterface
|
|
|
|
{
|
|
|
|
/**
|
2017-11-05 15:48:36 +01:00
|
|
|
* @param integer $pid
|
2015-04-09 08:51:45 +02:00
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isRunning($pid)
|
|
|
|
{
|
|
|
|
// Signal "0" is not sent to the process, but posix_kill checks the process anyway;
|
|
|
|
return posix_kill($pid, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-08-11 16:32:42 +02:00
|
|
|
* {@inheritdoc}
|
2015-04-09 08:51:45 +02:00
|
|
|
*/
|
|
|
|
public function kill($pid, $forcefully = false)
|
|
|
|
{
|
2016-08-11 16:32:42 +02:00
|
|
|
return posix_kill($pid, $forcefully ? 9 : 15);
|
2015-04-09 08:51:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether this posix_kill is available.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
public static function isAvailable()
|
|
|
|
{
|
|
|
|
return function_exists('posix_kill');
|
|
|
|
}
|
|
|
|
}
|