Debug for "Too many open files"

Programming languages, Coding, executables, and scripting.
Post Reply
Message
Author
I am a nobody
Posts: 43
Joined: 2012-04-13 03:44

Debug for "Too many open files"

#1 Post by I am a nobody »

Hi,

I need to check and fix "Too many open files" caused by bugs of TCP sockets were opened but not closed. What is the command line I can check how many socket file descriptors have been opened?

Thank you.

User avatar
dasein
Posts: 7775
Joined: 2011-03-04 01:06
Location: Terra Incantationum

Re: Debug for "Too many open files"

#2 Post by dasein »

And the search query you used before you posted is... what exactly?

I got some great results using tcp socket "too many files"

User avatar
GarryRicketson
Posts: 5872
Joined: 2015-01-20 22:16
Location: Durango, Mexico

Re: Debug for "Too many open files"

#3 Post by GarryRicketson »

You can try this:

Code: Select all

cat /proc/sys/fs/file-max 
For system wide limits
'ulimit'
Is a useful command

Code: Select all

man ulimit
--Try :

Code: Select all

ulimit -n
There is a file : 'limits.cnf' in /etc/security/
that can be modified.
Since you do not mention what version of Debian you are using, the above might not apply, I am using Debian 7 wheezy, and it is a valid command.
The Debian wiki,is often a valuable resources ?
https://wiki.debian.org/Limits
Also :
https://manpages.debian.org/jessie/libp ... .5.en.html

I am a nobody
Posts: 43
Joined: 2012-04-13 03:44

Re: Debug for "Too many open files"

#4 Post by I am a nobody »

GarryRicketson wrote:You can try this:

Code: Select all

cat /proc/sys/fs/file-max 
For system wide limits
'ulimit'
Is a useful command

Code: Select all

man ulimit
--Try :

Code: Select all

ulimit -n
There is a file : 'limits.cnf' in /etc/security/
that can be modified.
Since you do not mention what version of Debian you are using, the above might not apply, I am using Debian 7 wheezy, and it is a valid command.
The Debian wiki,is often a valuable resources ?
https://wiki.debian.org/Limits
Also :
https://manpages.debian.org/jessie/libp ... .5.en.html
Thanks all responses. It is Debian 8 Jessie, Sorry for not clear here, my intention is to debug a C++ program socket library which I suspect it might not close the socket properly. I need to run command to check how many socket descriptor files have been opened while I am running a test program to start the socket application and close it in a loop until it crashes the machine by error "Too many open files". So I am looking for the command line to display how many socket descriptor files are opened. I figured out that the lsof is the right command.

Thank you.

Bulkley
Posts: 6142
Joined: 2006-02-11 18:35

Re: Debug for "Too many open files"

#5 Post by Bulkley »

Is this a school project?

Have you mixed anything with your Jessie that does not belong? Added extra repositories? ppa's? Messed with something you shouldn't have?

Sorry for asking but this seems rather strange.

User avatar
dasein
Posts: 7775
Joined: 2011-03-04 01:06
Location: Terra Incantationum

Re: Debug for "Too many open files"

#6 Post by dasein »

I am a nobody wrote:Sorry for not clear here...
You were perfectly clear. You wanted to count the number of open TCP sockets, not to identify a maximum limit. Unfortunately, poster clarity doesn't always guarantee on-topic responses.
I am a nobody wrote:my intention is to debug a C++ program socket library...
As a pure question of economy of effort, I'd encourage you to focus on your own code first. (And if the socket library is your own code, then have at it.)
I am a nobody wrote:...start the socket application and close it in a loop until it crashes the machine
Purely pedantic point: abnormal termination of an application is not "crashing the machine" nor anywhere close to it.
I am a nobody wrote:I figured out that the lsof is the right command.
It's certainly a workable solution.

Dai_trying
Posts: 960
Joined: 2016-01-07 12:25

Re: Debug for "Too many open files"

#7 Post by Dai_trying »

You could simply open a terminal and type

Code: Select all

netstat -an | grep -i tcp | wc -l
you could even put it in a loop to keep updating at an interval of your choosing.

Post Reply