there are a bunch of other places you are iterating through this list looking for a specific entry see e g  in add pidstatistics below make a helper that returns the entry for a given pid or null if none exists then pidmatch is a trivial  return findpid ppid null  