Find the Process run by nohup command

我是研究僧i 提交于 2019-11-30 12:57:50

问题


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 PID but I couldnt get the process. Now how to kill the "server" now?


回答1:


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

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

nohup server &
print $! >> my_server.pid



回答2:


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

# lsof nohup.out

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

best regards!




回答3:


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

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.




回答4:


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

So 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.

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



来源:https://stackoverflow.com/questions/14151928/find-the-process-run-by-nohup-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!