Skip to content
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: list signals for bad sig name #513

Merged
merged 1 commit into from Mar 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 28 additions & 24 deletions bin/kill
Expand Up @@ -21,27 +21,14 @@ use Config;

# die if no signals or no arguments
die "No signals defined ?!?" unless defined $Config{"sig_name"};
die "$0: Too few arguments; try $0 -h\n" unless ( @ARGV );
usage() unless @ARGV;

my(@signals) = split(/\s+/,$Config{"sig_name"});
my(%hsignals) = map { $_ => 1 } @signals;
my($signal) = "TERM"; # default of SIGTERM

if ( $ARGV[0] =~ /^-l$/i ) { # list signals
for(my($i)=1;$i<=$#signals;$i++){
printf "%2d:%-6s%s",$i,$signals[$i],
( ($i % 8 == 0) || ($i == $#signals) )?"\n":" ";
}
exit 0;
}
elsif ( $ARGV[0] =~ /^-h$/i ) { # help me!
print "usage: $0 [-s signalname] PIDS ...
$0 [-signalname] PIDS ...
$0 [-signalnumber] PIDS ...
$0 PIDS ...
$0 [-l]
$0 [-h]
";
siglist();
exit 0;
}
elsif ( $ARGV[0] =~ /^-\d+$/ ) { # -signalnumber
Expand All @@ -55,8 +42,11 @@ elsif ( $ARGV[0] =~ /^-/ ) { # -NAME or -s NAME
$signal = shift @ARGV if ( lc $signal eq "s" ); # -s has signalname param.
$signal = uc $signal;
$signal =~ s/^SIG//; # remove the "SIG" from SIGNAME
die "$0: $signal: Unknown signal; $0 -l lists signals.\n"
unless ( $hsignals{$signal} );
unless ($hsignals{$signal}) {
print "$0: $signal: Unknown signal; valid signals...\n";
siglist();
exit 1;
}
}

die "$0: No PIDs specified.\n" unless ( @ARGV );
Expand All @@ -71,19 +61,35 @@ foreach ( @ARGV ) { # do the kills...

exit $ret;

sub usage {
print "usage: $0 [-s signalname] PID...
$0 [-signalname] PID...
$0 [-signalnumber] PID...
$0 PID...
$0 [-l]
";
exit 1;
}

sub siglist {
for(my($i)=1;$i<=$#signals;$i++){
printf "%2d:%-6s%s",$i,$signals[$i],
( ($i % 8 == 0) || ($i == $#signals) )?"\n":" ";
}
}

=head1 NAME

kill - send signals to a process

=head1 SYNOPSIS

B<kill>
[ B<-s> I<signalname> C<PIDS ...> ]
[ B<-signalname> C<PIDS ...> ]
[ B<-signalnumber> C<PIDS ...> ]
[ C<PIDS ...> ]
[ B<-s> I<signalname> C<PID...> ]
[ B<-signalname> C<PID...> ]
[ B<-signalnumber> C<PID...> ]
[ C<PID...> ]
[ B<-l> ]
[ B<-h> ]

=head1 DESCRIPTION

Expand All @@ -106,8 +112,6 @@ should be sent to the specified PID listing.

=item I<-l> Display a listing of all available signals on the current system.

=item I<-h> Display the usage help message.

=back

=head1 NOTES
Expand Down