in reply to Catching WINDOW close event and take actions

In a Tk gui ( or similarly with other GUI toolkits) you can catch the X button.
#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = new MainWindow; $mw->title("Close test"); $mw->geometry("400x250"); #prevents mw from closing $mw->protocol('WM_DELETE_WINDOW' => sub { print "do stuff here before the exit\n"; exit; }); MainLoop;
If you are just running an xterm , I don't know if it's possible easily. You probably would have to incorporate Term::ReadKey into your script and manually filter the keys.

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

Replies are listed 'Best First'.
Re^2: Catching WINDOW close event and take actions
by Anonymous Monk on Sep 15, 2011 at 21:31 UTC
    Thank you Zentara. Appreciate it.
Re^2: Catching CTRL+ALT+DEL close event and take actions
by Anonymous Monk on Sep 21, 2011 at 23:53 UTC

    Sorry for a little extension to this question, what is the signal name/code when we kill process using CTRL+ALT+DEL task manager Can we catch it and take cleanup actions

    Appreciate the inputs.

      CTRL-ALT-DEL is usually picked up by the Window Manager, or from console it is the reboot signal. A user cannot intercept that, see Control-Alt-Delete.

      In general, a user process is not able to intercept the Control-Alt-Delete sequence.

      Try this:

      #!/usr/bin/perl use warnings; use strict; sub handler_universal { print "\ngot a signal $_[0]\n"; $SIG{$_[0]} = \&handler_universal; } my @nami = keys(%SIG); #foreach( @nami){ print "$_\t$SIG{$_}\n"; } while(1){ for my $namesig (@nami) {$SIG{$namesig} = \&handler_universal;} }

      I'm not really a human, but I play one on earth.
      Old Perl Programmer Haiku ................... flash japh

        I think he is talking about deleting a process using taskmanager, or using http://live.sysinternals.com/pskill.exe

        Like CTRL+ALT+DELETE, you can't trap this either

        It ends the process without signaling it (Ctrl+C sends a signal)