我是靠谱客的博主 笑点低芹菜,这篇文章主要介绍prctl函数 linux,正确使用prctl()的方法,现在分享给大家,希望可以做个参考。

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函数内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(72)

评论列表共有 0 条评论

立即
投稿
返回
顶部