prctl的原型是
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强制转换为无符号数即可,或者完全跳过它们.由于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
最后
以上就是笑点低芹菜最近收集整理的关于prctl函数 linux,正确使用prctl()的方法的全部内容,更多相关prctl函数内容请搜索靠谱客的其他文章。
发表评论 取消回复