diff --git a/bin/pkill/pkill.c b/bin/pkill/pkill.c --- a/bin/pkill/pkill.c +++ b/bin/pkill/pkill.c @@ -827,6 +827,20 @@ usage(); } +static int +pidmax(void) +{ + int val; + size_t size; + + size = sizeof(val); + if (sysctlbyname("kern.pid_max", &val, &size, NULL, 0) < 0) { + return (PID_MAX); + } + + return (val); +} + static int takepid(const char *pidfile, int pidfilelock) { @@ -867,7 +881,7 @@ rval = strtol(line, &endp, 10); if (*endp != '\0' && !isspace((unsigned char)*endp)) errx(STATUS_ERROR, "Invalid pid in file `%s'", pidfile); - else if (rval < PID_MIN || rval > PID_MAX) + else if (rval < PID_MIN || rval > pidmax()) errx(STATUS_ERROR, "Invalid pid in file `%s'", pidfile); return (rval); }