Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I send a signal to a process ID in Perl 6?

Tags:

signals

raku

Perl 6 has ways to accept signals and to send a signal to a Proc::Async. Although the [p5-p6 perlfunc] docs says that kill works much like is does in Perl 5, it doesn't because you can't send a signal to an arbitrary process ID (doc issue filed). I had a particular program I wanted to write in Perl 6 (for giggles), but was forced to fall back to Perl 5 for lack of a reliable kill.

Short of shelling out to kill or tasklist (and taskkill), is this something we'll just have to do without. There's a kill in S29, but apparently not in the core docs. I haven't run across any docs of a more philosophical bent discussing what decisions drive various omissions.

I understand that a virtual machine that targets many systems has challenges when it comes to operating system specific stuff, but I don't know if that's the reason we can't have nice things such as kill (probably better named signal if you are starting over ;) and exec.

like image 877
brian d foy Avatar asked Apr 11 '17 22:04

brian d foy


People also ask

How do you find the PID of a process that sent signal?

A good choice is options=SA_RESTART . To know the PID of the process which sent a signal, set options=SA_SIGINFO , and use a sa_sigaction callback instead of sa_handler ; it will receive a siginfo_t struct, having a si_pid field. You can associate a data to the signal using sigqueue .

What function should you call to send a signal to another process?

Sending a Signal to Another Process: System Call kill() System call kill() takes two arguments. The first, pid, is the process ID you want to send a signal to, and the second, sig, is the signal you want to send.


1 Answers

I know you are looking for language support, but anyone finding this question who really needs a solution, can use NativeCall. For instance, to use the native kill on Linux (renamed to syskill for sanity):

use NativeCall;
# syskill( PID, SIGNAL ) -> 0 if sent, -1 if error, see "man 2 kill"
sub syskill(uint32, int32) returns int32 is native is symbol('kill') {};
like image 196
Dean Serenevy Avatar answered Oct 10 '22 01:10

Dean Serenevy