in reply to Starting a script according to processes
Maybe POE has an example to do this simple task?
I don't know how pslist outputs. But if it has a mode to give continuous output, like top, maybe you could set up a filehandle read on it, so you would only have to open it once( you may need to rewind the filehandle ). Then you could use IO::Select on it when it was readable.
Here is a simple idea using IPC::Open3. This uses relatively little cpu, at .1 second.
#!/usr/bin/perl use warnings; use strict; use IPC::Open3; my $pid = shift || $$; my $pid1 = open3(\*WRITE,\*READ,0,"/bin/sh"); #if \*ERROR is false, STDERR is sent to STDOUT while(1){ print WRITE "ps -o rss= -p $pid\n"; select(undef,undef,undef,.1); my $size = <READ>; #do your checks here and do whatever print "$size"; }
|
|---|