http://qs321.pair.com?node_id=988007


in reply to Calling Control-C in linux - Perl equivalent

Assuming you know the process ID, then:

kill 2, $pid;

Hard-coding the constant 2 may cause you trouble on non-Linux systems though. Better to use the constant defined in POSIX...

kill(POSIX::SIGINT, $pid);

If you have multiple processes to kill, kill takes a list...

kill(POSIX::SIGINT, @murder_victims);

Note that SIGINT is just a request for the process to end. The process can catch the signal and deliberately ignore it. If you want to force the process to die, then use SIGKILL instead.

SIGINT though is exactly what Ctrl+C does in the terminal. The terminal sees that you've pressed Ctrl+C and sends a SIGINT to the current foreground job.

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'