A Unix signal is a tiny message sent to a process. It can’t say much; it’s like a car horn honking: does that honk you hear mean “look out—the bridge collapsed,” “the light has changed—get going,” “stop driving—you’ve got a baby on the roof,” or “hello, world”? Fortunately, Unix signals are easier to interpret than that because there’s a different one for each of these situations. Different signals are identified by a name (such as
SIGINT, meaning “interrupt signal”) and a corresponding small integer (in the range from 1 to 16, 1 to 32, or 1 to 63, depending on your Unix flavor). Signals are typically sent when a significant event happens, such as pressing the interrupt character (typically Ctrl-C) on the terminal, which sends a
SIGINT to all the processes attached to that terminal. Some signals are sent automatically by the system, but they can come from another process.
You can send signals from your Perl process to another process, but you have to know the target’s process ID number. How to figure that out is a bit complicated, but say you know that you want to send a
SIGINT to process 4201. That’s easy enough:
kill 2, 4201 or die "Cannot signal 4201 with SIGINT: $!";
It’s named “kill” because one of the primary purposes of signals is to stop a process that’s gone on long enough. You can use the string
'INT' in place of the
2 there because signal number
SIGINT. If the process no longer exists, you’ll get a false return value, ...