patrix has asked for the wisdom of the Perl Monks concerning the following question:

hi, How can I disable ctrl+c in my programs? so that when someone does ctrl+c it doesn't terminate? thanks.

Replies are listed 'Best First'.
Re: disable ctrl+c in my program
by thinker (Parson) on Jan 15, 2003 at 20:24 UTC
    Hi patrix,

    the signal you want to catch is the interrupt signal.
    Just put in a line like
    $SIG{'INT'} = 'IGNORE';
    and the program will no longer terminate on Ctrl-C

    Hope this helps

    thinker
Re: disable ctrl+c in my program
by dragonchild (Archbishop) on Jan 15, 2003 at 19:53 UTC
    ctrl-c sends what's know as a signal to the OS. The OS then sends that signal to your program. Read up on the %SIG hash. I believe you're looking for $SIG{KILL}, though I could be mistaken.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

      Eh, no. SIGKILL is one of two signals you cannot ignore (the other is SIGSTOP). SIGKILL is what you get if you do kill -9 PID. ^C typically sends SIGINT. So, you would have to do SIG {INT} = 'IGNORE'.

      Abigail

Re: disable ctrl+c in my program
by zentara (Cardinal) on Jan 16, 2003 at 18:25 UTC
    Here is something to play with.
    #!/usr/bin/perl my $interrupted; local $SIG{INT} = sub { $interupted = 1 }; while (1) { print "hi\n"; sleep 1; if ($interrupted) { warn "ctrl-c pressed!\n" and $interrupted = 0 } }