Macos login from terminal (Terminal/iTerm) takes long time with high CPU When I open the terminal (iTerm/Terminal), login process consumes %100 cpu and waits for 1-2 minutes before the shell appears.
I have been googling for some time, I tried to remove asl files, reset user permissions, used custom login command with hushlogin flags... But no luck.
I have done dtrace on login process and saw that the process does a lot of file scanning.
Some example lines:
  678/0x1bd8:  open(&quot;/.vol/16777220/1716443\0&quot;, 0x8004, 0x0)         = 5 0
  678/0x1bd8:  getattrlistbulk(0x5, 0x7FFE4B00AE08, 0x7FFE30050000)      = 2 0
  678/0x1bd8:  getattrlistbulk(0x5, 0x7FFE4B00AE08, 0x7FFE30050000)      = 0 0
  678/0x1bd8:  open(&quot;/.vol/16777220/1716352\0&quot;, 0x8004, 0x0)         = 5 0
  678/0x1bd8:  getattrlistbulk(0x5, 0x7FFE4B00AE08, 0x7FFE30050000)      = 4 0

I have a large (8MB) dtrace logs file that I can share if you need it.
Any idea what would be happening?
(on Big Sur but the issue was there on Catalina as well.)
After more digging, it turned out that the slowness of login was caused by lsof.
login calls lsof at some point which takes very long time to finish.
After some trials and errors, I had to reset max file descriptors limit to default to solve the issue.
I don't know the exact relationship between lsof and max file descriptors limit but it turned out that large max file limits slow down lsof dramatically.