-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
kill 0, $pid should probably not throw exception #47
Comments
From perldoc -f kill "If SIGNAL is either the number 0 or the string ZERO (or SIGZZERO ), no signal is sent to the process, but kill checks whether it's possible to send a signal to it (that means, to be brief, that the process is owned by the same user, or we are the super-user). This is useful to check that a child process is still alive (even if only as a zombie) and hasn't changed its UID. See perlport for notes on the portability of this construct." |
Oh drat. I think you're right, that I'm teaching right now (as you know!), but as a workaround you can always use I need to think about whether changing this may break existing code, and if so should we do so. I may even ask @rjbs for spiritual guidance. ~ P |
Sorry for my late reply! My first thought is: if you're using kill 0, you're doing it for the return value. I'd want kill to be fatal on in void context. If you're using kill 0 in void context, you are probably confused. I realize that autodie is not big on "...in void context," however. (Perl 6 has a nice solution for this… :-/) I think it could break existing code. My gut tells me that it's unlikely. I think you could get away with this change. On the other hand, it's a complication to the nearly universal rule that "with autodie, affected routines go from 'return false' to 'die' on failure," which doesn't thrill me. Finally and maybe most importantly: I was unable to quickly find the implementation of autodie or Fatal's |
@rjbs: The reason why you probably failed to find the implementation of kill is that it is auto-generated. It is listed in %Returns_num_things_changed, so it fails if "$retval != (@_ - X)" [where X is the value listed in %Returns_num_things_changed]. |
Closed with pull request #72 |
Still happens. Neither "there" nor "done" appears in this program: njh@microcenter:/tmp$ cat autodie use strict; if(kill(0, 10000)) { njh@microcenter:/tmp$ ./autodie |
It appears the code at https://github.com/pjf/autodie/blob/master/lib/Fatal.pm#L1043 still expects to autodie when in a non-void context. |
Yes, that is what I'm saying. |
I could see a use case for the status quo, i.e., “die if $pid is gone”. Also, this interface has worked this way for a while, right? Were autodie.pm new, it would totally make sense to make this not throw, but given that the ship has (long since) sailed, IMO there’s not a compelling case for what is, strictly speaking, a breaking change. That aside, if this change does go through, please ensure that |
Maybe we need a docs fix with an example explaining how to do kill 0? |
Better, IMO, to document this in the POD as one of a list of “potential gotchas” than to change it. |
kill 0, $pid is an effective way to determine whether a process is still running and can accept signals from this process (without actually killing it). If the process exists, this returns true, and if the process does not, it would normally return false.... unless autodie is in use in which case it throws an exception and kills the program.
The text was updated successfully, but these errors were encountered: