php-src/ext/standard/tests/general_functions/proc_nice_basic.phpt
Nikita Popov 7575340427 Merge branch 'PHP-7.4'
* PHP-7.4:
  Check ps -p availability in proc_nice test
  Set AI_CANONNAME flag in socket_addrinfo test
  Add ipv6 skipif to test
  Improve privilege check in pcntl_setpriority() test
2020-08-05 12:12:24 +02:00

36 lines
989 B
PHP

--TEST--
proc_nice() basic behaviour
--CREDITS--
Italian PHP TestFest 2009 Cesena 19-20-21 june
Fabio Fabbrucci (fabbrucci@grupporetina.com)
Michele Orselli (mo@ideato.it)
Simone Gentili (sensorario@gmail.com)
--SKIPIF--
<?php
if(!function_exists('proc_nice')) die("skip. proc_nice not available ");
if(substr(strtoupper(PHP_OS), 0, 3) == 'WIN') die('skip. not for Windows');
exec('ps -p 1 -o "pid,nice"', $output, $exit_code);
if ($exit_code !== 0) {
die("skip ps -p is not available");
}
?>
--FILE--
<?php
function getNice($id)
{
$res = shell_exec('ps -p ' . $id .' -o "pid,nice"');
preg_match('/^\s*\w+\s+\w+\s*(\d+)\s+(\d+)/m', $res, $matches);
if (count($matches) > 2)
return $matches[2];
else
return -1;
}
$delta = 10;
$pid = getmypid();
$niceBefore = getNice($pid);
proc_nice($delta);
$niceAfter = getNice($pid);
var_dump($niceBefore == ($niceAfter - $delta));
?>
--EXPECT--
bool(true)