我想知道如何检查 getpriority()
返回的值 -1 是错误值还是合法值。来自手册:
RETURN VALUE
Since getpriority() can legitimately return the value -1, it is neces- sary to clear the external variable errno prior to the call, then check it afterwards to determine if -1 is an error or a legitimate value.
我真的不知道如何使用变量 errno
,因为我总是使用 perror(...)
来显示错误...
最佳答案
说到做到!清除 errno 的值,然后调用,然后进行检查。
#include <errno.h>
#include <sys/time.h>
#include <sys/resource.h>
errno = 0;
int val = getpriority();
if (val == -1 && errno) {
// we have an error!
}
关于C - UNIX - 检查 getpriority() 是否返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20126994/