Using signal, you can make your program more functional. To get all the signal under Linux, use the kill-l. Here is the output on my machine (which is not listed in the following 64):
Copy Code code as follows:
xuyang@xuyang-desktop:/$ kill-l
1) Sighup 2) SIGINT 3) Sigquit 4) Sigill 5) Sigtrap
6) SIGABRT 7) Sigbus 8) SIGFPE 9) SIGKILL SIGUSR1
SIGSEGV) SIGUSR2) sigpipe sigalrm) sigterm
Sigstkflt) sigchld) Sigcont SIGSTOP) SIGTSTP
Sigttin) Sigttou) Sigurg sigxcpu) Sigxfsz
SIGVTALRM) sigprof) sigwinch Sigio) SIGPWR
) Sigsys
Each of these signal is introduced here.
The following is an example of a ban on CTRL + C (CTRL + C will produce an int signal to the current program) to close the current program
Copy Code code as follows:
Sub Int_handler {
Print ("Don ' t interrupt!\n");
}
$SIG {' INT '} = ' Int_handler '; #another Way is $SIG {' INT '} = \&int_handler;
for ($x = 0; $x < $x + +) {
Print ("$x \ n");
Sleep 1;
}
One of the%sig is Perl's built-in hash, which is designed to handle signals. If you want to ignore a signal, you can write
Copy Code code as follows:
$SIG {' INT '} = ' IGNORE ';
To revert to the default condition, use the
Copy Code code as follows:
$SIG {' INT '} = ' DEFAULT ';
To send a CTRL + C to a program, in addition to using CTRL + C, you can also type
Copy Code code as follows:
The more practical value is SIGUSR1, SIGUSR2, the two signal are custom-defined. You can handle the two signals in any way you want in your program. And when you want to trigger this signal, just type it in Linux
Copy Code code as follows:
Can trigger this signal handler, you can open and close debugging information in this signal handler, or switch working mode and so on. Of course, because signal is the function of the operating system, the language here is not just for Perl, but for other languages as well. It's just a different grammar.