summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorjluehrs2 <jluehrs2@uiuc.edu>2007-08-17 18:26:04 -0500
committerjluehrs2 <jluehrs2@uiuc.edu>2007-08-17 18:26:04 -0500
commit1757478ae658a89400792db79651ccbf4a422ed2 (patch)
tree7e1183c17b31766a8d7e761e8d86dc45a15bf31d /lib
parent76a624b683ffa3ad213d8d9a711a82c0f9cbcb82 (diff)
downloadio-pty-easy-1757478ae658a89400792db79651ccbf4a422ed2.tar.gz
io-pty-easy-1757478ae658a89400792db79651ccbf4a422ed2.zip
make kill block on the subprocess death by default, and allow sending signals other than TERM
Diffstat (limited to 'lib')
-rw-r--r--lib/IO/Pty/Easy.pm22
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/IO/Pty/Easy.pm b/lib/IO/Pty/Easy.pm
index 36acd9a..64e09e8 100644
--- a/lib/IO/Pty/Easy.pm
+++ b/lib/IO/Pty/Easy.pm
@@ -260,17 +260,23 @@ sub is_active {
=head2 kill()
-Kills the process currently running on the pty (if any). After this call, C<read()> and C<write()> will fail, and a new process can be created on the pty with C<spawn()> once C<is_active> returns false.
+Sends a signal to the process currently running on the pty (if any). Optionally blocks until the process dies.
-Returns 1 if a process was actually killed, and 0 otherwise.
+C<kill()> takes two optional arguments. The first is the signal to send, in any format that the perl C<kill()> command recognizes (defaulting to "TERM"). The second is a boolean argument, where false means to block until the process dies, and true means to just send the signal and return.
+
+Returns 1 if a process was actually signaled, and 0 otherwise.
=cut
sub kill {
my $self = shift;
+ my ($sig, $non_blocking) = @_;
+ $sig = "TERM" unless defined $sig;
+
+ my $kills = kill $sig => $self->{pid} if $self->is_active;
+ $self->_wait_for_inactive unless $non_blocking;
- # SIGCHLD should take care of undefing pid
- kill TERM => $self->{pid} if $self->is_active;
+ return $kills;
}
# }}}
@@ -295,6 +301,14 @@ sub close {
}
# }}}
+# _wait_for_inactive() {{{
+sub _wait_for_inactive {
+ my $self = shift;
+
+ 1 while $self->is_active;
+}
+# }}}
+
# Ending documentation {{{
=head1 SEE ALSO