Reputation: 21
Assume that I have a perl script, which keep running in the background, say run.pl How can I interact with this script by calling it self? such as: perl run.pl -reload , perl run.pl -reset
Is it possible to do it? If yes, which modular should I study?
Thanks a lot!
Upvotes: 0
Views: 170
Reputation: 64563
There are several methods of interprocess communications in a operating system (in case of Linux/Unix this is pipes, FIFOs, signals, shared memory and several other). Perl supports all of them.
I think, that the best solution for your task is to use signals.
So you can intercept a signal in Perl:
sub INT_handler {
print("Don't Interrupt!\n");
}
$SIG{'INT'} = 'INT_handler';
And so you can send signals:
kill 9 => $pid; # send $pid a signal 9
kill -1 => $pgrp; # send whole job a signal 1
kill USR1 => $$; # send myself a SIGUSR1
kill HUP => @pids; # send a SIGHUP to processes in @pids
More about signals in Learning Perl, chapter 16.8 Sending and Receiving Signals.
There are not so many signals available in an OS (maximum 64), and signals that you can use for your own purposes even fewer.
If you need something more powerful, use sockets or message passing systems like ZeroMQ.
Upvotes: 1
Reputation: 15036
IPC (perldoc perlipc
) can be done by various methods:
I think the most simple way is handle for signal HUP in script, and after the signal is received, read some file for additional information. Of course, you must write this file before sending the signal.
Upvotes: 2
Reputation: 753
Since your perl-script runs in background you can interact with it directly. But, there are few workarounds:
Upvotes: 0