如何获得PID_MAX宏?

问题描述 投票:0回答:1

我想获取文件PID_MAX中存在的/sys/sys/proc.h宏的值。

我当前的代码(main.c):

#include <stdio.h>
#include <stdlib.h>

#include <sys/types.h> /* type pid_t */
#include <sys/proc.h> /* macro PID_MAX */
#include <sys/unistd.h> /* function getpid, getppid */

/*
gcc -Wall -Wextra main.c -o main
./main
*/

int main ()
{
    pid_t pidmax = PID_MAX;

    printf ( "Value = %d\n", pidmax );

    return 0;
}

返回以下错误:

error: 'PID_MAX' undeclared (first use in this function); did you mean 'UID_MAX'?

怎么可能?

恢复PID_MAX的另一种方法?

c freebsd
1个回答
0
投票

[没有独立于平台的方法来检索最大pid值。例如,在Linux下,您可以通过/proc/sys接口确定值]

$ sysctl kernel/pid_max
32768
© www.soinside.com 2019 - 2024. All rights reserved.