当前位置: 技术问答>linux和unix
如果知道一个进程的pid,用C怎么得到他的优先级?
来源: 互联网 发布时间:2014-11-18
本文导语: rt. | Standard C Library Functions getpriority(3C) NAME getpriority, setpriority - get or set process scheduling priority SYNOPSIS #include int g...
rt.
|
Standard C Library Functions getpriority(3C)
NAME
getpriority, setpriority - get or set process scheduling
priority
SYNOPSIS
#include
int getpriority(int which, id_t who);
int setpriority(int which, id_t who, int priority);
DESCRIPTION
The getpriority() function obtains the current scheduling
priority of a process, process group, or user. The set-
priority() function sets the scheduling priority of a pro-
cess, process group, or user.
Target processes are specified by the values of the which
and who arguments. The which argument may be one of the
following values: PRIO_PROCESS, PRIO_PGRP, or PRIO_USER,
indicating that the who argument is to be interpreted as a
process ID, a process group ID, or a user ID, respectively.
A 0 value for the who argument specifies the current pro-
cess, process group, or user.
If more than one process is specified, getpriority() returns
the highest priority (lowest numerical value) pertaining to
any of the specified processes, and setpriority() sets the
priorities of all of the specified processes to the speci-
fied value.
The default priority is 0; negative priorities cause more
favorable scheduling. While the range of valid priority
values is [-20, 20], implementations may enforce more res-
trictive limits. If the value specified to setpriority() is
less than the system's lowest supported priority value, the
system's lowest supported value is used; if it is greater
than the system's highest supported value, the system's
highest supported value is used.
Only a process with appropriate privileges can raise its
priority (that is, assign a lower numerical priority value).
RETURN VALUES
Upon successful completion, getpriority() returns an integer
in the range from -20 to 20. Otherwise, -1 is returned and
errno is set to indicate the error.
Upon successful completion, setpriority() returns 0. Other-
wise, -1 is returned and errno is set to indicate the error.
SunOS 5.8 Last change: 6 Mar 1996 1
Standard C Library Functions getpriority(3C)
ERRORS
The getpriority() and setpriority() functions will fail if:
ESRCH No process could be located using the which and who
argument values specified.
EINVAL
The value of the which argument was not recognized, or
the value of the who argument is not a valid process
ID, process group ID, or user ID.
In addition, setpriority() may fail if:
EPERM A process was located, but neither the real nor effec-
tive user ID of the executing process is the
privileged user or match the effective user ID of the
process whose priority is being changed.
EACCES
A request was made to change the priority to a lower
numeric value (that is, to a higher priority) and the
current process does not have appropriate privileges.
USAGE
The effect of changing the scheduling priority may vary
depending on the process-scheduling algorithm in effect.
Because getpriority() can return -1 on successful comple-
tion, it is necessary to set errno to 0 prior to a call to
getpriority(). If getpriority() returns -1, then errno can
be checked to see if an error occurred or if the value is a
legitimate priority.
SEE ALSO
nice(1), renice(1), fork(2)
NAME
getpriority, setpriority - get or set process scheduling
priority
SYNOPSIS
#include
int getpriority(int which, id_t who);
int setpriority(int which, id_t who, int priority);
DESCRIPTION
The getpriority() function obtains the current scheduling
priority of a process, process group, or user. The set-
priority() function sets the scheduling priority of a pro-
cess, process group, or user.
Target processes are specified by the values of the which
and who arguments. The which argument may be one of the
following values: PRIO_PROCESS, PRIO_PGRP, or PRIO_USER,
indicating that the who argument is to be interpreted as a
process ID, a process group ID, or a user ID, respectively.
A 0 value for the who argument specifies the current pro-
cess, process group, or user.
If more than one process is specified, getpriority() returns
the highest priority (lowest numerical value) pertaining to
any of the specified processes, and setpriority() sets the
priorities of all of the specified processes to the speci-
fied value.
The default priority is 0; negative priorities cause more
favorable scheduling. While the range of valid priority
values is [-20, 20], implementations may enforce more res-
trictive limits. If the value specified to setpriority() is
less than the system's lowest supported priority value, the
system's lowest supported value is used; if it is greater
than the system's highest supported value, the system's
highest supported value is used.
Only a process with appropriate privileges can raise its
priority (that is, assign a lower numerical priority value).
RETURN VALUES
Upon successful completion, getpriority() returns an integer
in the range from -20 to 20. Otherwise, -1 is returned and
errno is set to indicate the error.
Upon successful completion, setpriority() returns 0. Other-
wise, -1 is returned and errno is set to indicate the error.
SunOS 5.8 Last change: 6 Mar 1996 1
Standard C Library Functions getpriority(3C)
ERRORS
The getpriority() and setpriority() functions will fail if:
ESRCH No process could be located using the which and who
argument values specified.
EINVAL
The value of the which argument was not recognized, or
the value of the who argument is not a valid process
ID, process group ID, or user ID.
In addition, setpriority() may fail if:
EPERM A process was located, but neither the real nor effec-
tive user ID of the executing process is the
privileged user or match the effective user ID of the
process whose priority is being changed.
EACCES
A request was made to change the priority to a lower
numeric value (that is, to a higher priority) and the
current process does not have appropriate privileges.
USAGE
The effect of changing the scheduling priority may vary
depending on the process-scheduling algorithm in effect.
Because getpriority() can return -1 on successful comple-
tion, it is necessary to set errno to 0 prior to a call to
getpriority(). If getpriority() returns -1, then errno can
be checked to see if an error occurred or if the value is a
legitimate priority.
SEE ALSO
nice(1), renice(1), fork(2)