#!/usr/bin/perl $myself = "student"; chomp ($mytty = `tty`); # gets: /dev/pts/5 $mytty =~ s/.dev.//; # gets: pts/5 =preview We'll run the command: ps -u $myself -o 'pid,tty' It will produce output like this: PID TT 419 pts/3 401 pts/3 398 ? 399 pts/3 437 ? 479 pts/5 513 pts/5 1175 ? =cut @lines = split /\n/, `ps -u $myself -o 'pid,tty'`; shift @lines; # gets rid of header line foreach $entry (@lines) { ($pid, $term) = $entry =~ /^\D*(\d+)\s+(\S+)/; next if ($term =~ /^[?]/ || $term eq $mytty); print "kill 9, $pid\n"; # for testing # kill 9, $pid; # production version }