help: how does "kill -n" work?

F

fieldtrip

Guest
Hi all,

Let's pretend that I have a process with a PID of 12345. I have been told that if I run the following:

Code:
kill -n20 12345
that kill will elevate in priority due to the assignment of the non-default nice value (via -n) and then preform a hard kill.

My line of thinking is that a "hard kill" is kill -9, whereas the default for kill is -15. My question is that if no switch is given for the "kill level" with the above command, will it give the equivalent of a -9 or -15 kill? Furthermore, how can I test this myself? In other words, how can I kill a process and then determine whether it was killed with SIGKILL or SIGTERM?
 


F

fieldtrip

Guest
First of all, I am wondering if I received misinformation as the man page for kill gives the following in regard to the -n switch:

""" -n where n is larger than 1. All processes in process group
n are signaled. When an argument of the form '-n' is
given, and it is meant to denote a process group, either
the signal must be specified first, or the argument must
be preceded by a '--' option, otherwise it will be taken
as the signal to send."""

Secondly, echo '$&' gives the exit status of the previous command. I.E.
Code:
[email protected] ~/T/hey> echo '$&'
$&
fish: Job 2, “geany lalala” terminated by signal SIGTERM (Polite quit request)
Furthermore, GrumpyOldMan, I appreciate your input. You may notice, however, that I included the gist of your claim in my OP. Thanks again :)
 
R

ryanvade

Guest
Code:
~$
kill -l
1) SIGHUP    2) SIGINT    3) SIGQUIT    4) SIGILL    5) SIGTRAP
6) SIGABRT    7) SIGBUS    8) SIGFPE    9) SIGKILL   10) SIGUSR1
11) SIGSEGV   12) SIGUSR2   13) SIGPIPE   14) SIGALRM   15) SIGTERM
16) SIGSTKFLT   17) SIGCHLD   18) SIGCONT   19) SIGSTOP   20) SIGTSTP
21) SIGTTIN   22) SIGTTOU   23) SIGURG   24) SIGXCPU   25) SIGXFSZ
26) SIGVTALRM   27) SIGPROF   28) SIGWINCH   29) SIGIO   30) SIGPWR
31) SIGSYS   34) SIGRTMIN   35) SIGRTMIN+1   36) SIGRTMIN+2   37) SIGRTMIN+3
38) SIGRTMIN+4   39) SIGRTMIN+5   40) SIGRTMIN+6   41) SIGRTMIN+7   42) SIGRTMIN+8
43) SIGRTMIN+9   44) SIGRTMIN+10   45) SIGRTMIN+11   46) SIGRTMIN+12   47) SIGRTMIN+13
48) SIGRTMIN+14   49) SIGRTMIN+15   50) SIGRTMAX-14   51) SIGRTMAX-13   52) SIGRTMAX-12
53) SIGRTMAX-11   54) SIGRTMAX-10   55) SIGRTMAX-9   56) SIGRTMAX-8   57) SIGRTMAX-7
58) SIGRTMAX-6   59) SIGRTMAX-5   60) SIGRTMAX-4   61) SIGRTMAX-3   62) SIGRTMAX-2
63) SIGRTMAX-1   64) SIGRTMAX
From the man page:
NAME
kill - send a signal to a process

SYNOPSIS
kill [options] <pid> [...]

DESCRIPTION
The default signal for kill is TERM. Use -l or -L to list available
signals. Particularly useful signals include HUP, INT, KILL, STOP,
CONT, and 0. Alternate signals may be specified in three ways: -9,
-SIGKILL or -KILL. Negative PID values may be used to choose whole
process groups; see the PGID column in ps command output. A PID of -1
is special; it indicates all processes except the kill process itself
and init.
Not misinformation. TERM = SIGTERM IE terminate: kill -15 = kill -TERM = kill
Where as kill -9 = kill -SIGKILL --> hard kill

kill -15 (kill) nicely asks the process to exit while kill -9 (SIGKILL) forces the process to close.

http://en.wikipedia.org/wiki/SIGTERM#POSIX_signals

-n (where n is a number greater than 0) allows you to set he elevation or "urgency" of the kill command. Either to terminate or abort the process.
 
Last edited:
F

fieldtrip

Guest
Thanks again for the reply.

What I meant by 'misinformation' is the whole bit about the -n switch of kill "pairing" kill with the nice command. In other words, I was told (rather, I read) that passing the -n option to kill would "combine" nice with kill with the aim of elevating the priority of the kill command above that of the priority of the process that I (or whoever) was aiming to kill. As if one could not, say, pipe nice into kill (manually).

Again, the man page for kill mentions nothing (so far as I have seen) to declare that there is any switch/option (let alone that of -n) that will "combine" nice with kill. Therefore I am led to wonder if I have read misinformation upon that point; I came here to ask for some clarification.

I am not confused on the fact that kill -15 = SIGTERM and that default bahaviour of kill = SIGTERM, nor am I claiming that the default behaviour of kill being SIGTERM is misinformation.
 
R

ryanvade

Guest
Thanks again for the reply.

What I meant by 'misinformation' is the whole bit about the -n switch of kill "pairing" kill with the nice command. In other words, I was told (rather, I read) that passing the -n option to kill would "combine" nice with kill with the aim of elevating the priority of the kill command above that of the priority of the process that I (or whoever) was aiming to kill. As if one could not, say, pipe nice into kill (manually).

Again, the man page for kill mentions nothing (so far as I have seen) to declare that there is any switch/option (let alone that of -n) that will "combine" nice with kill. Therefore I am led to wonder if I have read misinformation upon that point; I came here to ask for some clarification.

I am not confused on the fact that kill -15 = SIGTERM and that default bahaviour of kill = SIGTERM, nor am I claiming that the default behaviour of kill being SIGTERM is misinformation.
No, kill does not use nice in any way. It merely works with the PID and the kill() system call.
http://man7.org/linux/man-pages/man2/kill.2.html
 
Last edited:
M

MikeyD

Guest
I found this to be a good resource for the different (or most used) SIG levels and their differences:
http://linuxcommand.org/lc3_lts0100.php

Specifically...

Signal #

Name

Description

1SIGHUP
Hang up signal. Programs can listen for this signal and act upon it. This signal is sent to processes running in a terminal when you close the terminal.

2SIGINT
Interrupt signal. This signal is given to processes to interrupt them. Programs can process this signal and act upon it. You can also issue this signal directly by typing Ctrl-c in the terminal window where the program is running.

15SIGTERM
Termination signal. This signal is given to processes to terminate them. Again, programs can process this signal and act upon it. This is the default signal sent by the kill command if no signal is specified.

9SIGKILL
Kill signal. This signal causes the immediate termination of the process by the Linux kernel. Programs cannot listen for this signal.
 
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Staff online

Members online


Top