pcntl_setpriority() - pcntl进程控制
pcntl_setpriority()
(PHP 5, PHP 7)
修改任意进程的优先级
说明
pcntl_setpriority(int $priority[,int $pid= getmypid()[,int $process_identifier= PRIO_PROCESS]]): boolpcntl_setpriority()设置进程号为$pid的进程的优先级。
参数
$priority$priority通常时-20至20这个范围内的值。默认优先级是0,值越小代表优先级越高。由于不同的系统类型以及内核版本下优先级可能不同,因此请参考您系统的setpriority(2)手册以获取详细的规范。
如果没有指定,默认是当前进程的进程号。
$process_identifierPRIO_PGRP
(译注:获取进程组优先级),PRIO_USER
(译注:获取用户进程优先级)或PRIO_PROCESS(译注:默认值;获取进程优先级)
三者之一。
返回值
成功时返回TRUE
,或者在失败时返回FALSE
。
参见
pcntl_getpriority()
获取任意进程的优先级
As for the renice function by leandro dot pereira at gmail dot com, this isn't true. pcntl_setpriority() doesn't set the nice level of a process, but instead sets the base priority of it. At first glance this might seem like the same thing, but on a system level, they are actually quite different. In fact, if you're looking to use pcntl_setpriority() to prioritize your process (a tool or a daemon or what-not), I wouldn't recomend using setpriority at all, but renice it instead. Let the system manage priorities and you'll end up with the results you were looking for. This applies only to POSIX based systems only (as does the function presented by leandro dot pereira at gmail dot com as well).
The following snippet may be used under older versions of PHP to provide similar functionality. Tested only under Linux.
内容声明:本文中引用的各种信息及资料(包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主体(包括但不限于公司、媒体、协会等机构)的官方网站或公开发表的信息。部分内容参考包括:(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供参考使用,不准确地方联系删除处理!本站为非盈利性质站点,本着为中国教育事业出一份力,发布内容不收取任何费用也不接任何广告!)