Skip to content

Instantly share code, notes, and snippets.

@pvdb
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pvdb/295a687285b7ed04a726 to your computer and use it in GitHub Desktop.
Save pvdb/295a687285b7ed04a726 to your computer and use it in GitHub Desktop.
Get the number of TCP connections owned by current Ruby process
#
# This first version should work on Mac OS X and Linux, but it spawns a process
#
# the number of TCP connections owned by the process.
def Process.tcp_count() `lsof -l -n -P -p #{Process.pid} -a -i tcp | egrep -v '^COMMAND' | wc -l`.chomp.to_i ; end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment