#
# as this is a standalong file..that may ot be able to access the LONCAPA
# module, I'm leaving the temp directory knoweldge uncentralized
#    - R. Fox 7/1/2011
#

use strict;

my $loncapa_tempdir = '/home/httpd/perl/tmp'; # configure the temp dir here.

my $result=`ls -l /proc/*/fd/* | grep $loncapa_tempdir`;
my @result=split("\n",$result);
my (@pids,@files);
foreach my $line (@result) {
	if ($line=~m-/proc/(\d+)/fd-) {
		push(@pids,$1);
		$line=~m-(/home/httpd/perl/tmp/.*)-;
		push(@files,$1);
	}
}

$result=`wget --http-user=lonadm -q --http-passwd=litelite --output-document=- http://localhost/server-status`;

@result=split('<tr>',$result);

foreach my $line (@result) {
	if ($line =~ m -</b><td>(\d+)<td>-) {
		my $curpid=$1;
		print ("curpid is $1\n");
		for (my $i=0;$i<=$#pids;$i++) {
			my $pid=@pids[$i];
			my $file=@files[$i];
			if ($curpid == $pid) {
				$line=~m-<td nowrap>([^<]*)</tr>-;
				print("$pid has a tmp file $file, last known request is $1\n");
			}
		}
	}
}

