macOS error: “Too many files in system”

“Too many files in system”. If it happens that macOS console trows this quite unspecific error, you can discover what process to blame for that one by running:

lsof -n | perl -pe '$x = <>; while(<>) { ($cmd, $pid, $rest) = split(/\s+/); $cmds{$pid} = $cmd; $pids{$pid}++;} while( ($key, $val) = each %pids) { if ($val > $max) { $max = $val; $maxpid = $key; } } print "pid: $maxpid ($cmds{$maxpid}) has the most ($max) filedescriptors \n";'

Too many files macOS error

Found in an answer by stevep98 in Reddit.