Attached. Sample output:
1) macbookpoe:~/projects/misc/support% perl shutdown-another.pl
Fri Aug 19 08:47:39 2011 - Controller started. Press Ctrl+C to exit.
Fri Aug 19 08:47:40 2011 - Ticker is working.
Fri Aug 19 08:47:41 2011 - Ticker is working.
Fri Aug 19 08:47:42 2011 - Ticker is working.
^CFri Aug 19 08:47:42 2011 - Controller caught sigint. Shutting down...
Fri Aug 19 08:47:42 2011 - Ticker is shutting down. Please be patient...
Fri Aug 19 08:47:43 2011 - Ticker has finished shutting down.
Fri Aug 19 08:47:43 2011 - Controller is being garbage collected.
Fri Aug 19 08:47:43 2011 - Ticker session is being destroyed.
1) macbookpoe:~/projects/misc/support%
--
Rocco Caputo
On Aug 19, 2011, at 04:02, Rizwan Hisham wrote:
> Dear List,
> How do I kill a running session from inside another session. There is no
> parent child relation between the two session, they totally independent from
> each other. Cant seem to find anyway to do it.
>
> If its possible then kindly provide a small sample code as well :)
>
> Thanks
>
> --
> Best Ragards
> Rizwan Qureshi
> VoIP/Asterisk Engineer
> Axvoice Inc.
>
> V: +92 (0) 6767 26
> E: rizwanhas...@gmail.com
> W: www.axvoice.com
#!/usr/bin/env perl
use POE;
POE::Session->create(
inline_states => {
_start => sub {
$_[KERNEL]->alias_set("ticker");
$_[KERNEL]->delay(tick => 1);
},
tick => sub {
_log("Ticker is working.");
$_[KERNEL]->delay(tick => 1);
},
shutdown => sub {
# Clean up our resources so we can exit cleanly.
_log("Ticker is shutting down. Please be patient...");
$_[KERNEL]->delay(tick => undef);
# Pretend shutdown takes some time.
$_[KERNEL]->delay(faux_shutdown => 1);
},
faux_shutdown => sub {
_log("Ticker has finished shutting down.");
},
_stop => sub {
_log("Ticker session is being destroyed.");
},
},
);
POE::Session->create(
inline_states => {
_start => sub {
$_[KERNEL]->alias_set("controller");
$_[KERNEL]->sig(INT => "got_sigint");
_log("Controller started. Press Ctrl+C to exit.");
},
got_sigint => sub {
_log("Controller caught sigint. Shutting down...");
$_[KERNEL]->post( ticker => "shutdown" );
$_[KERNEL]->sig_handled();
},
_stop => sub {
_log("Controller is being destroyed.");
},
},
);
POE::Kernel->run();
exit;
sub _log {
my $message = join "", @_;
print scalar(localtime), " - $message\n";
}