prctl
的原型是
int prctl(int option, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5);
在man page中,而在头文件中,它被声明为可变参数函数:
extern int prctl (int __option, ...) __THROW;
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; }