#!/usr/bin/perl use warnings; use strict; use IPC::Open3; my $pid = $$; my $pid1 = open3(0, \*READ,0,"top -d 2 -b -p $pid "); #if \*ERROR is false, STDERR is sent to STDOUT while(1){ my @words = split(/\s+/,); $words[0] ||= 0; if($words[0] =~ /$pid/){print "$words[4] $words[9]\n"} #print "$words[0]\n"; } waitpid($pid, 1); # It is important to waitpid on your child process, # otherwise zombies could be created.