mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-23 04:19:27 +01:00
ProcessManager: add kill
command
This commit is contained in:
parent
dc7cdd8a2c
commit
42dbf468b2
@ -35,7 +35,7 @@ sub ps_cmd {
|
|||||||
push @processes, "$pid: $self->{processes}->{$pid}->{commands}->[0]";
|
push @processes, "$pid: $self->{processes}->{$pid}->{commands}->[0]";
|
||||||
}
|
}
|
||||||
if (@processes) {
|
if (@processes) {
|
||||||
return "Running processes: ", join '; ', @processes;
|
return "Running processes: " . join '; ', @processes;
|
||||||
} else {
|
} else {
|
||||||
return "No running processes.";
|
return "No running processes.";
|
||||||
}
|
}
|
||||||
@ -43,7 +43,21 @@ sub ps_cmd {
|
|||||||
|
|
||||||
sub kill_cmd {
|
sub kill_cmd {
|
||||||
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
|
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
return "Coming soon.";
|
my $usage = "Usage: kill <pids...>";
|
||||||
|
|
||||||
|
my @pids;
|
||||||
|
while (1) {
|
||||||
|
my $pid = $self->{pbot}->{interpreter}->shift_arg($stuff->{arglist}) // last;
|
||||||
|
push @pids, $pid;
|
||||||
|
}
|
||||||
|
return $usage if not @pids;
|
||||||
|
|
||||||
|
foreach my $pid (@pids) {
|
||||||
|
return "No such pid $pid." if not exists $self->{processes}->{$pid};
|
||||||
|
}
|
||||||
|
|
||||||
|
kill 'INT', @pids;
|
||||||
|
return "Killed.";
|
||||||
}
|
}
|
||||||
|
|
||||||
sub add_process {
|
sub add_process {
|
||||||
@ -62,6 +76,10 @@ sub execute_subroutine {
|
|||||||
sub execute_process {
|
sub execute_process {
|
||||||
my ($self, $stuff, $subref) = @_;
|
my ($self, $stuff, $subref) = @_;
|
||||||
|
|
||||||
|
if (not exists $stuff->{commands}) {
|
||||||
|
$stuff->{commands} = [ $stuff->{command} ];
|
||||||
|
}
|
||||||
|
|
||||||
pipe(my $reader, my $writer);
|
pipe(my $reader, my $writer);
|
||||||
my $pid = fork;
|
my $pid = fork;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user