prctl
的原型(prototype)是
int prctl(int option, unsigned long arg2, unsigned long arg3,
unsigned long arg4, unsigned long arg5);
在man page而在 header它被声明为可变参数函数:
extern int prctl (int __option, ...) __THROW;
- 当我只需要 2 个参数时,是否必须使用 5 个参数来调用它?
- 是否需要将 args 转换为
unsigned long
?
最佳答案
只需传递您必须传递的内容并在其余参数中写入 0 转换为 unsigned long
或完全跳过它们。由于 prctl
被声明为可变参数函数,它将相应地处理这种情况。
const char* name = "The user";
if (prctl(PR_SET_NAME, (unsigned long) name,
(unsigned long)0, (unsigned long)0, (unsigned long)0) == -1)
{
// handle error
perror("prctl failed");
return -1;
}
或
const char* name = "The user";
if (prctl(PR_SET_NAME, (unsigned long) name) == -1)
{
// handle error
perror("prctl failed");
return -1;
}
关于prctl() 的正确使用方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36551394/