如何停止作为守护进程运行的程序

ste*_*ang 6 process daemon

我已经iperf以守护程序模式启动,iperf -s -D现在我想停止该服务。我尝试使用,sudo kill pid但它既不工作也不抱怨。当我检查时,守护进程仍在运行ps -ef | grep iperf

由于它不是由 Linux 启动的,因此我无法service像其他守护程序一样找到它。

我怎么能阻止呢?

rah*_*hmu 11

不要用kill -9!此命令仅用于某些特定的极端情况。

根据手册页(在我的 Solaris 机器上):

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.
Run Code Online (Sandbox Code Playgroud)

当您不指定任何信号时,kill 将向kill -15您的进程发送 SIGTERM ( )。您可以发送比 SIGKILL ( kill -9)更少暴力的更具攻击性的信号。

为什么要避免kill -9?

SIGKILL 是一个非常暴力的信号。它不能被进程捕获,这意味着收到它的进程必须立即丢弃所有内容并退出。它不需要时间来释放它锁定的资源(如网络套接字或文件),也不需要通知其他进程退出。通常,它会使您的机器处于不稳定状态。打个比方,您可以说使用 SIGKILL 杀死进程与使用电源按钮(与shutdown命令相反)关闭机器一样糟糕。

事实上,应该尽可能避免SIGKILL 。相反,如文章中所述,建议您尝试kill -2,如果不起作用kill -1

我见过人们总是急于发送 SIGKILL(即使在日常清理脚本中!)。我每天都和我的队友为此争吵。请不要kill -9盲目使用。

  • 我会在你的陈述中添加条件。不要使用“kill -9”,除非您尝试过其他相关信号,或者除非您知道不允许该进程干净终止的后果是什么并且它们是可以接受的。 (2认同)