⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 setpriority.html

📁 posix标准英文,html格式
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy, see www.w3.org"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 --><!-- Copyright (c) 2001-2004 IEEE and The Open Group, All Rights Reserved --><title>getpriority</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="getpriority"></a> <a name="tag_03_241"></a><!-- getpriority --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2004 Edition<br>Copyright &copy; 2001-2004 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_241_01"></a>NAME</h4><blockquote>getpriority, setpriority - get and set the nice value</blockquote><h4><a name="tag_03_241_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><div class="box"><code><tt><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> #include &lt;<a href="../basedefs/sys/resource.h.html">sys/resource.h</a>&gt;<br><br> int getpriority(int</tt> <i>which</i><tt>, id_t</tt> <i>who</i><tt>);<br> int setpriority(int</tt> <i>which</i><tt>, id_t</tt> <i>who</i><tt>, int</tt> <i>value</i><tt>); <img src="../images/opt-end.gif"alt="[Option End]" border="0"></tt></code></div><tt><br></tt></blockquote><h4><a name="tag_03_241_03"></a>DESCRIPTION</h4><blockquote><p>The <i>getpriority</i>() function shall obtain the nice value of a process, process group, or user. The <i>setpriority</i>()function shall set the nice value of a process, process group, or user to <i>value</i>+ {NZERO}.</p><p>Target processes are specified by the values of the <i>which</i> and <i>who</i> arguments. The <i>which</i> argument may be oneof the following values: PRIO_PROCESS, PRIO_PGRP, or PRIO_USER, indicating that the <i>who</i> argument is to be interpreted as aprocess ID, a process group ID, or an effective user ID, respectively. A 0 value for the <i>who</i> argument specifies the currentprocess, process group, or user.</p><p>The nice value set with <i>setpriority</i>() shall be applied to the process. If the process is multi-threaded, the nice valueshall affect all system scope threads in the process.</p><p>If more than one process is specified, <i>getpriority</i>() shall return value {NZERO} less than the lowest nice valuepertaining to any of the specified processes, and <i>setpriority</i>() shall set the nice values of all of the specified processesto <i>value</i>+ {NZERO}.</p><p>The default nice value is {NZERO}; lower nice values shall cause more favorable scheduling. While the range of valid nice valuesis [0,{NZERO}*2-1], implementations may enforce more restrictive limits. If <i>value</i>+ {NZERO} is less than the system's lowestsupported nice value, <i>setpriority</i>() shall set the nice value to the lowest supported value; if <i>value</i>+ {NZERO} isgreater than the system's highest supported nice value, <i>setpriority</i>() shall set the nice value to the highest supportedvalue.</p><p>Only a process with appropriate privileges can lower its nice value.</p><p><sup>[<a href="javascript:open_code('PS')">PS|TPS</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">Any processes or threads using SCHED_FIFO or SCHED_RR shall be unaffected by a call to <i>setpriority</i>(). This is not consideredan error. A process which subsequently reverts to SCHED_OTHER need not have its priority affected by such a <i>setpriority</i>()call. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p><p>The effect of changing the nice value may vary depending on the process-scheduling algorithm in effect.</p><p>Since <i>getpriority</i>() can return the value -1 on successful completion, it is necessary to set <i>errno</i> to 0 prior to acall to <i>getpriority</i>(). If <i>getpriority</i>() returns the value -1, then <i>errno</i> can be checked to see if an erroroccurred or if the value is a legitimate nice value.</p></blockquote><h4><a name="tag_03_241_04"></a>RETURN VALUE</h4><blockquote><p>Upon successful completion, <i>getpriority</i>() shall return an integer in the range -{NZERO} to {NZERO}-1. Otherwise, -1 shallbe returned and <i>errno</i> set to indicate the error.</p><p>Upon successful completion, <i>setpriority</i>() shall return 0; otherwise, -1 shall be returned and <i>errno</i> set toindicate the error.</p></blockquote><h4><a name="tag_03_241_05"></a>ERRORS</h4><blockquote><p>The <i>getpriority</i>() and <i>setpriority</i>() functions shall fail if:</p><dl compact><dt>[ESRCH]</dt><dd>No process could be located using the <i>which</i> and <i>who</i> argument values specified.</dd><dt>[EINVAL]</dt><dd>The value of the <i>which</i> argument was not recognized, or the value of the <i>who</i> argument is not a valid process ID,process group ID, or user ID.</dd></dl><p>In addition, <i>setpriority</i>() may fail if:</p><dl compact><dt>[EPERM]</dt><dd>A process was located, but neither the real nor effective user ID of the executing process match the effective user ID of theprocess whose nice value is being changed.</dd><dt>[EACCES]</dt><dd>A request was made to change the nice value to a lower numeric value and the current process does not have appropriateprivileges.</dd></dl></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_03_241_06"></a>EXAMPLES</h4><blockquote><h5><a name="tag_03_241_06_01"></a>Using getpriority()</h5><p>The following example returns the current scheduling priority for the process ID returned by the call to <a href="../functions/getpid.html"><i>getpid</i>()</a>.</p><pre><tt>#include &lt;sys/resource.h&gt;...int which = PRIO_PROCESS;id_t pid;int ret;<br>pid = getpid();ret = getpriority(which, pid);</tt></pre><h5><a name="tag_03_241_06_02"></a>Using setpriority()</h5><p>The following example sets the priority for the current process ID to -20.</p><pre><tt>#include &lt;sys/resource.h&gt;...int which = PRIO_PROCESS;id_t pid;int priority = -20;int ret;<br>pid = getpid();ret = setpriority(which, pid, priority);</tt></pre></blockquote><h4><a name="tag_03_241_07"></a>APPLICATION USAGE</h4><blockquote><p>The <i>getpriority</i>() and <i>setpriority</i>() functions work with an offset nice value (nice value -{NZERO}). The nice valueis in the range [0,2*{NZERO} -1], while the return value for <i>getpriority</i>() and the third parameter for <i>setpriority</i>()are in the range [-{NZERO},{NZERO} -1].</p></blockquote><h4><a name="tag_03_241_08"></a>RATIONALE</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_241_09"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_241_10"></a>SEE ALSO</h4><blockquote><p><a href="nice.html"><i>nice</i>()</a>, <a href="sched_get_priority_max.html"><i>sched_get_priority_max</i>()</a>, <a href="sched_setscheduler.html"><i>sched_setscheduler</i>()</a>, the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/sys/resource.h.html"><i>&lt;sys/resource.h&gt;</i></a></p></blockquote><h4><a name="tag_03_241_11"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 4, Version 2.</p></blockquote><h4><a name="tag_03_241_12"></a>Issue 5</h4><blockquote><p>Moved from X/OPEN UNIX extension to BASE.</p><p>The DESCRIPTION is reworded in terms of the nice value rather than <i>priority</i> to avoid confusion with functionality in thePOSIX Realtime Extension.</p></blockquote><div class="box"><em>End of informative text.</em></div><hr size="2" noshade><center><font size="2"><!--footer start-->UNIX &reg; is a registered Trademark of The Open Group.<br>POSIX &reg; is a registered Trademark of The IEEE.<br>[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>]</font></center><!--footer end--><hr size="2" noshade></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -