10

The Mac OS X Internals book states that the maximum process identifier is 30,000 and after that the kernel will start re-using pids. But checking on my own system, via:

ps a | grep ps | grep -v grep | awk '{print $1}'

I can see that I have pids that go higher. Does anyone know if there is a pid_max explicitly set somewhere, like in Linux?

2 Answers 2

17

Looking at sys/proc_internal.h in xnu-1699.24.23, I find that PID_MAX is 99999. The value is used in kern_fork.c in the function forkproc. Looking at that function, process IDs are not assigned equal to PID_MAX, so the highest possible pid is 99998.

4
  • 5
    The book is out of date, it did use to be 30000 (xnu-792 - Tiger) and changed to 99999 when xnu-1228 was released (Leopard) Commented May 11, 2012 at 21:23
  • macOS Catalina uses xnu-6153. Links for the code in the answer: sys/proc_internal.h; kern_fork. Kyle's answer appears still to be correct in this version. Commented Oct 23, 2020 at 14:29
  • Note also, looking at forkproc, that it appears PIDs must be positive. Commented Oct 23, 2020 at 14:41
  • *Except the kernel task, which has PID of zero. Commented Oct 23, 2020 at 14:43
6

Kyle's answer is still valid as of today. In case you want to verify that, here is a shell script:

#!/bin/bash

pid=0
for i in {1..100000}; do
  : &
  if [ $! -lt $pid ]; then
    echo "Min pid: $!"
    echo "Max pid: $pid"
    break
  fi
  pid=$!
done

This prints:

Min pid: 100
Max pid: 99998

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.