1 | 1 | simandl | #!/usr/bin/env perl |
2 | | | |
3 | | | (undef,$btime)=split(/ /,`cat /proc/stat |grep btime`); |
4 | | | |
5 | | | opendir DIR,"modules"; |
6 | | | @mods=sort grep(/^[a-z]\w*$/,readdir DIR); |
7 | | | closedir DIR; |
8 | | | |
9 | | | print "-----module----- -PID- ------command----- pri -----starttime----- -virt- -real-\n"; |
10 | | | foreach $name (@mods) { |
11 | | | ($pid,$cmd,$prio,$start,$vsize,$rsize)=(); |
12 | | | if (-e "modules/$name/running.pid") { |
13 | | | open FILE,"modules/$name/running.pid"; |
14 | | | $pid=<FILE>; |
15 | | | close FILE; |
16 | | | push @PIDs,$pid; |
17 | | | open FILE,"/proc/$pid/stat"; |
18 | | | $line=<FILE>; |
19 | | | close FILE; |
20 | | | $line=~ s/.*(\(.*\))//, $cmd=$1; |
21 | | | @status=split / /,$line; |
22 | | | $prio=$status[16]; |
23 | | | $start=$status[20]/100+$btime; |
24 | | | ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($start); |
25 | | | $year+=1900; |
26 | | | $start=sprintf "%4d-%02d-%02d %02d:%02d:%02d",$year,$mon,$mday,$hour,$min,$sec; |
27 | | | $vsize=int($status[21]/1024)."k"; |
28 | | | $rsize=($status[22]*4)."k"; |
29 | | | } |
30 | | | printf"%-15s%7s%19s%4s%20s%7s%7s\n",$name,$pid,$cmd,$prio,$start,$vsize,$rsize; |
31 | | | } |
32 | | | print "\nAll PIDs:\n",join " ",@PIDs,"\n\n"; |