Working with ulimits and open file descriptors

Yet another in the long list of things I always forget how to do between needing to do them...

Cheatsheet to working with ulimits and too many open files.
list how many open file descriptors a process has
lsof -P [pid] | wc -l
ls /proc/[pid]/fd | wc -l (cheaper)
look at limits for a specific process
cat /proc/[pid]/limits
set limits for a user
futz with /etc/security/limits.conf or /etc/security/limits.d/*
show ulimits for the current process
ulimit -a
set number of open file handle limit for the current process (and processes spawned from this one)
ulimit -n 16384 (note - only root can raise hard limits)
Hope that helps, future self.

No comments: