You seem to have two questions here:
- how to share memory between the Perl program and your C program, and
- how to signal the Perl program there is new data available
Assuming you're on a system that allows SysV IPC calls, you can use IPC::ShareLite to share a chunk of memory between the two processes.
As usual with shared memory, you will have to ensure locks are in place. The module manual page for IPC::ShareLite seems to explain the intricacies and the method calls fairly well.
Regarding signaling the Perl program there is new data available, there's nothing stopping you from using... signals to achieve that! Your C program can send a SIGUSR1 to the Perl program, and the Perl program will access the shared memory and do stuff when receiving the signal, and sleep otherwise.
Have a look at perldoc perlipc for that, but the gist of it is something along these lines:
use strict;
use warnings;
use IPC::ShareLite;
# init shared memory
sub do_work {
# use shared memory, as you just received a signal
# indicating there's new data available
my $signame = shift;
# ...
}
$SIG{USR1} = \&do_work; # when signaled with SIGUSR1, call do_work()
# else just sleep
while(1) { sleep 1; }
Hope this helps,
-marco-