gpt4 book ai didi

C - UNIX - 检查 getpriority() 是否返回错误

转载 作者:太空宇宙 更新时间:2023-11-04 07:23:13 24 4
gpt4 key购买 nike

我想知道如何检查 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com