#!/usr/bin/perl

use strict;

if ($#ARGV != 0) 
  {
  print "Usage: $0 username\n" ;
  exit(1);
  }

my $actuser = shift;

my $err = &killuser($actuser);
print "Code $err\n";

exit 0;


sub killuser # (user)
  {
  # can only be done as root
  # Kommandozeile fuer ps ggf. anpassen:
  my $pscommand = '/bin/ps -eo pid,user';

  my $user = @_[0];
  my @entry = ();
  my $name = '';
  my $pid = 0;
  my $line = '';
  my $signal = '';
  
  foreach $signal ("TERM","HUP","KILL")
    {
    print "Sending $signal signal to all processes ...\n";
    open(PS, "$pscommand |");
    @entry = grep(/$user/,<PS>);
    close PS;
    return(0) if ($#entry == -1); 
    foreach $line (@entry)
      {
      chomp($line);
      $line =~ s/  */ /g;
      $line =~ s/^ *//g;
      ($pid,$name) = split(/ /,$line);
      print "$pid ";
      kill($signal,$pid);
      }
    print "\n"; 
    }
  return(0);	
  } 
    
    
    
    
