#!/usr/bin/perl
use CGI qw(:standard);

@users = split('\n',`ps -e -o "%u"`);
shift(@users);
%proc_count = ();
$total = 0;

foreach $user(@users)
{
	$total += 1;
	if(exists $proc_count{$user})
	{
		$proc_count{$user} += 1;
	}
	else
	{
		$proc_count{$user} = 1;
	}
}

print start_html("user_list");

print <<"END"
Select user from list to show his running processes.<br>
Number in brackets () indicates number of runing processes owned by the user.<br>
Total number of processes found: <b>$total</b>.<br><br>
<form action="proc_list.cgi" method="get">

<select name="username">
<option value="">select user</option>
END
;

foreach $user(sort keys %proc_count)
{
print <<"END"
<option value="$user">$user($proc_count{$user})</option>
END
;
}

print <<"END"
</select>
or type in user name
<input type="text" name="username_typed"></input>
<input type="submit" value="select user"></input>
</form>
END
;

print end_html();



