#!/usr/bin/perl use strict; my $data; my $pid = open F, "perl safe.pl -|"; eval { local $SIG{ALRM} = sub { kill 9, $pid; close F; $data .= " Exceeded CPU Time"; die; }; alarm(1); read (F,$data,254); close F; alarm(0); }; print $data; #### #!/usr/bin/perl use strict; use Safe; my $cp = new Safe; $cp->permit_only(qw( null stub scalar pushmark wantarray const gvsv gv gelem padsv padav padhv padany pushre rv2gv rv2sv av2arylen rv2cv anoncode prototype refgen srefgen ref bless glob readline rcatline regcmaybe regcreset regcomp match qr subst substcont trans sassign aassign chop schop chomp schomp defined undef study pos preinc i_preinc predec i_predec postinc i_postinc postdec i_postdec pow multiply i_multiply divide i_divide modulo i_modulo repeat add i_add subtract i_subtract concat stringify left_shift right_shift lt i_lt gt i_gt le i_le ge i_ge eq i_eq ne i_ne ncmp i_ncmp slt sgt sle sge seq sne scmp bit_and bit_xor bit_or negate i_negate not complement atan2 sin cos rand srand exp log sqrt int hex oct abs length substr vec index rindex sprintf formline ord chr crypt ucfirst lcfirst uc lc quotemeta rv2av aelemfast aelem aslice each values keys delete exists rv2hv helem hslice unpack pack split join list lslice anonlist anonhash splice push pop shift unshift sort reverse grepstart grepwhile mapstart mapwhile range flip flop and or xor cond_expr andassign orassign method entersub leavesub caller warn die reset lineseq nextstate dbstate unstack enter leave scope enteriter iter enterloop leaveloop return last next redo dump goto exit umask binmode tie untie tied sselect select getc read enterwrite leavewrite prtf print time tms localtime gmtime sleep entereval leaveeval entertry leavetry)); $cp->rdo("/tmp/tmp.pl"); print $@ if $@;