#!/usr/local/bin/perl
$debug = 1;
print "Content-type: text/html\n\n" if $debug;
$hw_name = "hw3.cgi";
$term = `/bin/ps -wuagx | grep "run-hw3.cgi"`;
@lines = split /\n/,$term;
($info) = grep "m#\nperl\s+$hw_name#", @lines;
print "$info
" if $debug;
print "------------
\n" if $debug;
@fields = split /\s+/,$info;
if ($debug) {
foreach (@fields) {
print "$_
\n";
}
print "------------
\n";
}
if ($fields[6] eq "?") {
if (-e $hw_name) {
if (-x $hw_name) {
exec "./$hw_name";
} else {
error("You must make $hw_name executable");
}
} else {
error("You must name your homework $hw_name");
}
} else {
$where = `whereis ps`;
print "$where\n";
print "\n\nThis script can only be run from the web\n\n";
}
sub error() {
my($msg) = @_;
print <