>> -------- Original Message -------- >> Subject: Calling subroutine every second using alarm fails >> From: Kelly Jones <kelly.terry.jo...@gmail.com> >> Date: Wed, April 01, 2009 5:48 am >> To: beginners@perl.org >> >> >> I want a script that constantly accepts user input, but runs a >> subroutine every second to do other work. > > > what I thought is to fork a child to do the stuff. > > my $child = fork; > die "cant fork $!" unless defined $child; > > if ($child) { # in parent > while(<>) { > # do something > } > } else { # in child > while( some_condition ) { > # do stuff > sleep 1; > } > exit 0; > } > > > regards, > Jeff.
I'm trying to avoid fork() because, in the real app, I want my signal handler to share/change variables within the main program. Any way to do it using signals? Alarm seems like the perfect solution w/ the minor problem that it doesn't actually seem to work. I realize I could use fork() and then do IPC for variable sharing, but yuck! -- We're just a Bunch Of Regular Guys, a collective group that's trying to understand and assimilate technology. We feel that resistance to new ideas and technology is unwise and ultimately futile. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/