#!/usr/bin/perl use warnings; use strict; use Proc::ProcessTable; my $time = time(); my $xtermparentpid; my $pttydev; system("xterm -T $time &"); #specify title so you can match for it my $t = new Proc::ProcessTable; foreach my $p (@{$t->table}) { # print "pid->",$p->pid," ttydev->",$p->ttydev," cmdline->", # $p->cmndline," ppid->",$p->ppid,"\n"; if($p->cmndline =~ /$time/){$xtermparentpid = $p->pid} } foreach my $p (@{$t->table}) { if($p->ppid == $xtermparentpid){$pttydev = $p->ttydev} } open(FH,">$pttydev") or warn $!; for(1..1000){print STDOUT $_,"\n"; print FH $_.'a',"\n";sleep 1;} close FH;