Click to See Complete Forum and Search --> : open files limit of a running process
neuron
05-08-2007, 11:18 AM
Im trying to find out what is the limit of open files allowed for an already running process, the bash ulimit command with the -n option can be used to set that value for the current shell and apps forking from that shell, but what if there is an already started process and we need to know how many fd it is allowd to use ?
cybertron
05-08-2007, 06:08 PM
Well, unless you've changed the limit since the process started, it will be the same as the limit for whatever user the process is running as. Other than that I'm not aware of any way to do this. /proc would have been my best guess but I don't see anything in there that would be helpful.
Out of curiosity, why do you need to do this? Can you not restart the process as a user whose limit you know? If you can restart it but still need some programmatic way to access the limit you could wrap it in a script that would write ulimit -n to a file somewhere and read from that.
neuron
05-10-2007, 04:57 AM
I've tried /proc too, i couldn't find anything neither, the value must be there somewhere, and its defenatly not an environment variable, other wise the process would be able to change it, but then i wonder why the ulimit is a bash built in command ...
the process is run with owner root, and yes, its not a good idea to restart it now, and i know it will crash if it reaches the limit and run out of file descriptors. I'm monitoring how many files its opening using lsof -p <pid>, but till now it didn't reach the max, but it will. i have already the script that sets the limits correctly and everything and then fires the app, but I'm not sure it was started by that script or invoked directly. either way, i think this value is monitored by the kernel, it should be stored somewhere... no ?
cybertron
05-13-2007, 01:01 PM
Yeah, it's possible there's a kernel API somewhere that you could query this from, but I don't know what it would be. If I were you I'd just assume that the limit hasn't changed since the process started and that whatever the limit is for that user right now it was then too.