Personally, if it is important to keep the two parts of your application as separate processes, I'd use udp (which should work on any platform) for the IPC.
The monitoring script would have something like this:
#! perl -slw use strict; use Time::HiRes qw[ time sleep ]; use IO::Socket; $|++; my $port = 54321; socket( SOCKET, PF_INET, SOCK_DGRAM, getprotobyname('udp') ) or die "s +ocket: $!"; setsockopt( SOCKET, SOL_SOCKET, SO_REUSEADDR, 1 ); bind( SOCKET, sockaddr_in( $port, inet_aton( 'localhost' ) ) ) or die +$^E; my $true = 1; ioctl( SOCKET, 0x8004667e, \$true ); my $pid = system 1, "/perl64/bin/perl.exe", "monitored.pl",$port; my $time; while( kill 0, $pid ) { my $addr = recv( SOCKET, $time, 1024, 0 ) or select '','','',0.001 +; printf "\rProgress:%s\t", $time; } print "All done.";
And the monitored script only needs minimal code, that will have little or no effect on its performance if it is being run stand alone:
#! perl -slw use strict; ## monitored.pl use IO::Socket; $|++; my $port = shift; socket( SOCKET, PF_INET, SOCK_DGRAM, getprotobyname('udp') ) or die "s +ocket: $!"; my $runtime = rand( 120 ); for my $milli ( 0 .. $runtime * 1000 ) { select '','','', 0.001; send( SOCKET, sprintf( "\r%.f%%\t", $milli / ($runtime*10) ), 0, s +ockaddr_in( $port, inet_aton( 'localhost' ) ) ) or die "send: $^E"; }
Simple, reliable and minimally invasive.
In reply to Re: Shared memory and asynchronous access
by BrowserUk
in thread Shared memory and asynchronous access
by vef445
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |