#!/usr/bin/env perl

  (undef,$btime)=split(/ /,`cat /proc/stat |grep btime`);

  opendir DIR,"modules";
  @mods=sort grep(/^\w+$/,readdir DIR);
  closedir DIR;

  print "-----module----- -PID- ------command----- pri -----starttime----- -virt- -real-\n";
  foreach $name (@mods) {
    ($pid,$cmd,$prio,$start,$vsize,$rsize)=();
    if (-e "modules/$name/running.pid") {
      open FILE,"modules/$name/running.pid";
      $pid=<FILE>;
      close FILE;
      push @PIDs,$pid;
      open FILE,"/proc/$pid/stat";
      $line=<FILE>;
      close FILE;
      $line=~ s/.*(\(.*\))//, $cmd=$1;
      @status=split / /,$line;
      $prio=$status[16];
      $start=$status[20]/100+$btime;
      ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($start);
      $year+=1900;
      $start=sprintf "%4d-%02d-%02d %02d:%02d:%02d",$year,$mon,$mday,$hour,$min,$sec;
      $vsize=int($status[21]/1024)."k";
      $rsize=($status[22]*4)."k";
    }
    printf"%-15s%7s%19s%4s%20s%7s%7s\n",$name,$pid,$cmd,$prio,$start,$vsize,$rsize;
  }
  print "\nAll PIDs:\n",join " ",@PIDs,"\n\n";
