1824488 Members
3338 Online
109672 Solutions
New Discussion юеВ

About the kill command

 
nash11
Frequent Advisor

About the kill command

I use the the command "kill -8" to kill the system process , but I found that it will kill other processes simultaneously ( may be the -8 is too powerful ) , please suggest which parameter ( -1, -2 ... ) is lowest "power" to kill the process ? thx
8 REPLIES 8
Jannik
Honored Contributor

Re: About the kill command

man kill:

signum signame Name Description
___________________________________________________________________________
0 SIGNULL Null Check access to pid
1 SIGHUP Hangup Terminate; can be trapped
2 SIGINT Interrupt Terminate; can be trapped
3 SIGQUIT Quit Terminate with core dump; can be trapped
9 SIGKILL Kill Forced termination; cannot be trapped
15 SIGTERM Terminate Terminate; can be trapped
24 SIGSTOP Stop Pause the process; cannot be trapped
25 SIGTSTP Terminal stop Pause the process; can be trapped
26 SIGCONT Continue Run a stopped process
jaton
Kenan Erdey
Honored Contributor

Re: About the kill command

you can use kill without parameter to kill the process safely, it uses signal number as 15.
Computers have lots of memory but no imagination
Peter Godron
Honored Contributor

Re: About the kill command

Hi,
see:
man kill

0 SIGNULL Null Check access to pid
1 SIGHUP Hangup Terminate; can be trapped
2 SIGINT Interrupt Terminate; can be trapped
3 SIGQUIT Quit Terminate with core dump; can be trapped
9 SIGKILL Kill Forced termination; cannot be trapped
15 SIGTERM Terminate Terminate; can be trapped
24 SIGSTOP Stop Pause the process; cannot be trapped
25 SIGTSTP Terminal stop Pause the process; can be trapped
26 SIGCONT Continue Run a stopped process
If you kill a parent process this may trigger the kill on the attached processes.
Torsten.
Acclaimed Contributor

Re: About the kill command

Sinal "8" (FPE) is surely not the right one to kill your process.

First you should try simply

# kill

which is equivalent to "-15" SIGTERM. This gives your process the possibility to terminate gracefully.

If this doesn't help, use

# kill -9

kill command is used to send signals to processes, not only to "kill" them.

see "man kill"

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
Arunvijai_4
Honored Contributor

Re: About the kill command

Hi Nash,

Floating Point Exception (FPE) is not a best way to kill a process. It will dump a core.
You can try with -15 or -9 with kill command,

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
James R. Ferguson
Acclaimed Contributor

Re: About the kill command

Hi:

First, make usre that you isolate the process that you *really* want. Use the XPG4 (UNIX95) options of 'ps' achieves this.

Never kill with 'kill -9' except as a last resort. A 'kill -9' cannot be ignored or trapped and it doesn't give a process any chance to clean up shared memory segments or remove temporary files.

Instead, use a multi-level kill, starting with a hangup; then a simple 'kill -15'; and as a last resort a 'kill -9'.

The following code accomplishs the above. If any level of killing succeeds, the script exits. If there is any chance that you have multiple processes by the same name, this code accomodates that too.

# cat .killer
#!/usr/bin/sh
myproc=`basename ${1}`
[ -z "${1}" ] && { echo "no process specified!"; exit 1; }
mypid=`UNIX95= ps -C ${myproc} -o pid=`
if [ ! -z "${mypid}" ]; then
kill -1 ${mypid} 2>/dev/null
sleep 3
kill -15 ${mypid} 2>/dev/null
sleep 3
kill -9 ${mypid} 2>/dev/null
fi
exit 0

...You can see how this works by doing:

# sleep 120 &
# ./killer sleep

(or)

# nohup /usr/bin/sleep 120 &
# ./killer sleep

If you wish to integrate this into a subroutine in an existing script, change the 'exit' to a 'return' within the subroutine

Regards!

...JRF...
Mustafa Gulercan
Respected Contributor

Re: About the kill command

The kill command sends a signal to each process specified by a pid
process identifier. The default signal is SIGTERM, which normally
terminates processes that do not trap or ignore the signal.

pid is a process identifier, an unsigned or negative integer that can
be one of the following:

> 0 The number of a process.

= 0 All processes, except special system processes, whose
process group ID is equal to the process group ID of the
sender.

=-1 All processes, except special system processes, if the user
has appropriate privileges. Otherwise, all processes,
except special system processes, whose real or effective
user ID is the same as the user ID of the sending process.

<-1 All processes, except special system processes, whose
process group ID is equal to the absolute value of pid and
whose real or effective user ID is the same as the user of
the sending process.

Process numbers can be found with the ps command (see ps(1)) and with
the built-in jobs command available in some shells.

first try #kill
and then try #kill -9 >process_id>
but -9 will kill other dependency process.

regards;
mustafa
Bill Hassell
Honored Contributor

Re: About the kill command

Note also that a kill signals just the specific process (assuming you are killing with a positive process ID). However, some processes are not independent so killing one process (regardless of the kill signal) may cause dependent processes to also terminate. For example, killing a parent of a process will also terminate the child process.


Bill Hassell, sysadmin