1 Given the following code, how do I use Perl's flock function to exclusively lock "file" (comprised of a list of fund tickers) so that, while subroutine "process" reads from "file" and executes, the user can't mangle "file" via subroutine "alter_file"?
2 Should "process" hang for some unknown reason, how can the user terminate whatever processs(es) UserAgent "$html_source" is executing? (Exact SIG code much appreciated.)
use Tk; use LWP::Simple; use LWP::UserAgent; use FileHandle; $mw = MainWindow -> new;what $screw = $mw -> Button ( -text => "screw up ticker file", -command => [ \&alter_file ] ) -> pack; $go = $mw -> Button ( -text => "go", -command => [ \&process ] ) -> pack; $stop = $mw -> Button ( -text > "stop", -command => [ \&stop_process ] ) -> pack; $html_source = new LWP::UserAgent; MainLoop; sub alter_file { open ( HANDLE1, "+< file" ); # OPEN FOR READ/WRITE while ( <HANDLE1> ) { chop; chop; chop; # SCREW UP file } close HANDLE1; } sub process { open ( HANDLE2, "< file" ); # OPEN FOR READ-ONLY # WANT TO LOCK HANDLE2 SO THAT USER CAN'T SCREW UP file WHILE # THE FOLLOWING CODE EXECUTES while ( <HANDLE2> ) { $html_source -> get ( "http://quicktake.morningstar.com/ FundNet/Snapshot.aspx?Symbol=$_" ); # DO WHATEVER WITH $html_source CONTENT } close HANDLE2; } sub stop_process { # WANT TO SIGNAL USERAGENT $html_source TO STOP (OR DESTROY?) # ITSELF # (AS A SIDE QUESTION: ASSUMING IT'S STILL OPEN, HOW WOULD I # THEN CLOSE HANDLE2?) }
In reply to Two questions on interprocess communication by cypress
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |