Skip to content

Instantly share code, notes, and snippets.

@equinox79
Last active December 23, 2015 19:39
Show Gist options
  • Save equinox79/6683640 to your computer and use it in GitHub Desktop.
Save equinox79/6683640 to your computer and use it in GitHub Desktop.
プロセス毎のファイルディスクリプタ利用数を表示(5個以上開いているもののみ)
#!/usr/bin/env perl
#
# Name: fdcnt.pl
#
# Usage:
# $ sudo perl fdcnt.pl | sort -rn
#
# Licence: MIT
#
use strict;
use warnings;
my $pid_list = `ps -ef|grep -v grep|awk '{print \$2,\$8,\$9,\$10,\$11,\$12,\$13,\$14}'`;
foreach my $line ( map { [split /\s/] } split( /\n/, $pid_list ) ) {
my $proc_path = "/proc/$$line[0]/fd";
next unless ( -d $proc_path );
my $fd_count = `ls $proc_path|wc -l`;
$fd_count =~ s/\n//g;
if ( $fd_count > 5 ) {
print sprintf (
"%s\t%s\t%s\n",
( $fd_count, $$line[0], join( " ", @$line[ 1 .. $#$line ] ) )
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment