正确使用prctl()的方法
作者:互联网
prctl的原型是
int prctl(int option, unsigned long arg2, unsigned long arg3,
unsigned long arg4, unsigned long arg5);
extern int prctl (int __option, ...) __THROW;
>当我只需要2个参数时,是否必须用5个参数调用它?
>是否需要将args强制转换为unsigned long?
解决方法:
只需传递您必须传递的内容,然后在其余参数中将0强制转换为无符号数即可,或者完全跳过它们.由于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;
}
标签:variadic,system-calls,glibc,c-3,linux 来源: https://codeday.me/bug/20191118/2031037.html