Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have launched iperf in daemon mode with iperf -s -D and now I want to stop the service. I tried to use sudo kill pid but it neither work nor complain. The daemon is still running when I check through ps -ef | grep iperf.

As it is not launched by Linux, I cannot find it through service as other daemons.

How could I stop it?

share|improve this question

5 Answers 5

up vote 3 down vote accepted

Don't use kill -9! This command is meant to be used in some specific extreme cases only.

According to the man page (on my Solaris box):

DESCRIPTION
 The kill utility sends a signal to the process or  processes
 specified by each pid operand.

 For each pid operand, the kill utility will perform  actions
 equivalent to the kill(2) function called with the following
 arguments:

 1.  The value of the pid operand will be  used  as  the  pid
     argument.

 2.  The sig argument  is  the  value  specified  by  the  -s
     option,  the  -signal_name option, or the -signal_number
     option, or, if none of these options  is  specified,  by
     SIGTERM.

 The signaled process must belong to the current user  unless
 the user is the super-user.

When you don't specify any signal, kill will send SIGTERM (kill -15) to your process. There are more aggressive signals you can send that are less violent than SIGKILL (kill -9).

Why avoid kill -9?

SIGKILL is a very violent signal. It cannot be caught by the process, which means that the process that recieves it has to drop everything instantly and exit. It doesn't take the time to liberates resources it has locked (like network sockets or files) nor to inform other processes of exiting. Often, it will leave your machine in an unstable state. Drawing an analogy, you could say that killing a process with SIGKILL is as bad as turning off the machine with the Power button (as opposed to the shutdown command).

As a matter of facts, SIGKILL should be avoided as much as you can. Instead, as mentioned in the article, it's suggested that you try kill -2 and if that doesn't work kill -1.

I've seen people rush into sending SIGKILL all the time (even in daily clean up scripts!). I fight with my teammates daily about this. Please, don't use kill -9 blindly.

share|improve this answer
    
I would add conditions to your statement. Don't use kill -9 unless you have tried other relevant signals or unless you know what the consequences of not allowing that process to terminate cleanly are and they are acceptable. –  Shawn J. Goff Feb 17 '12 at 12:30
    
Yes absolutely. You should not hesitate to edit the answer and improve it. –  rahmu Feb 17 '12 at 14:13

Although generally not recommended, you can always resort to kill -9 <pid> to really kill a process. Do understand, however, that you are forcefully shutting the process down, meaning that it will not gracefully exit.

share|improve this answer

use kill -9 <pid of iperf> to kill the process. With a signal number of 9 (KILL), the kill cannot be caught by the process; use this to kill a process that a plain kill doesn't terminate.

share|improve this answer

As it seems that this iperf process is not responding to your "termination" signal (the default signal sendby a kill <pid> command). It usually means that the process is crashed somehow or stuck in input/output accessing.

You just need to be more violent and send a "KILL" signal:

kill -9 <pid>

Or

kill -KILL <pid>

This will terminate the process without waiting for it to properly finish.

share|improve this answer
1  
If I'm not mistaken, if the process is stuck in I/O, then even kill -9 will not kill it. –  bbaja42 Feb 17 '12 at 10:10
    
You are right, so stuck on input/output ... not real I/O ;) –  Ouki Feb 17 '12 at 10:27

You should use the kill command with -9 option.

$ kill -9 pid

I sends the SIGKILL signal to kill the process which is the strongest signal of all.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.