Linux 找到通过 nohup 命令运行的进程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14151928/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 18:11:29  来源:igfitidea点击:

Find the Process run by nohup command

linuxprocessbackgroundpsnohup

提问by 2vision2

I run a server executable in Centos using the following command "nohup server &". Now I need to kill the process "server". But I tried "ps -a"command to get the PIDbut I couldnt get the process. Now how to kill the "server"now?

我使用以下命令在 Centos 中运行服务器可执行文件"nohup server &"。现在我需要终止进程"server"。但是我尝试"ps -a"命令来获取PID但我无法获取过程。现在如何杀死"server"现在?

采纳答案by Usman Saleem

ps auxwww|grep -i 'server'should return all process which has serverin them. Otherwise, server may have already stopped.

ps auxwww|grep -i 'server'应该返回其中包含的所有进程server。否则,服务器可能已经停止。

You should be able to determine the PID (and store it in a file) as follows:

您应该能够确定 PID(并将其存储在文件中),如下所示:

nohup server &
print $! >> my_server.pid

回答by Mikhail

The best way to launch a server in centos is with the service command.

在 centos 中启动服务器的最佳方式是使用 service 命令。

So service httpd start

所以 service httpd start

There is a chance that you want to write your program as a daemon

您可能希望将程序编写为守护进程

A daemon (or service) is a background process that is designed to run autonomously,with little or not user intervention. The Apache web server http daemon (httpd) is one such example of a daemon. It waits in the background listening on specific ports, and serves up pages or processes scripts, based on the type of request.

守护进程(或服务)是一个后台进程,旨在自主运行,很少或不需要用户干预。Apache Web 服务器 http 守护程序 (httpd) 就是一个这样的守护程序示例。它在后台等待特定端口,并根据请求类型提供页面或处理脚本。

See http://www.netzmafia.de/skripten/unix/linux-daemon-howto.html

http://www.netzmafia.de/skripten/unix/linux-daemon-howto.html

回答by Arpit

There is no definitive way to catch the exact process with the help of pscommand, but you can use the following:

ps命令的帮助下没有确定的方法来捕获确切的过程,但您可以使用以下方法:

ps -a | grep "server"

You will get a list of all the processes running with the name "server"

您将获得所有以“服务器”名称运行的进程的列表

Or, you can use any other keywords as well to grep the ps output.

或者,您也可以使用任何其他关键字来 grep ps 输出。

回答by ignivs

If a nohup.out file was created, you may run in bash:

如果创建了 nohup.out 文件,您可以在 bash 中运行:

# lsof nohup.out

it will return the pid which created/is running the file

它将返回创建/正在运行文件的 pid

best regards!

此致!