check your sysctl
kern.pid_max: 99999
kern.randompid: 0
$ sysctl kern.pid_max
kern.pid_max: 99999
$ sysctl kern.randompid
kern.randompid: 822
# sysctl kern.randompid=0
$ sysctl kern.randompid
kern.randompid: 405
Sounds to me like you expect some process to always get the same PID if you don't randomize PIDs. That's a flawed assumption. Just add or remove a service from boot process, or have one thatnow found that PID is randomized everytime, so I can't kill some process by its pid.
fork()
s based on some external state, and you'll get different PIDs.It's not (the grep(1) would have filtered it out). You may be looking at the PID of grep(1) itself though. Which is why you often see constructs likeMy mistake, the pid oflldb
always changes whenps aux | grep lldb
, the result pid is actually the pid ofps
ps -aux | grep <someproc> | grep -v grep
. But the better solution is to use pgrep(1) instead. The best solution is to use the PID file of the process (daemons typically create these), kill $(cat /var/run/<daemon>)
.