Reputation: 5023
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?
Upvotes: 11
Views: 45535
Reputation: 646
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!
Upvotes: 15
Reputation: 1655
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
Upvotes: 19
Reputation: 8038
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
Upvotes: 1
Reputation: 6260
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.
Upvotes: 5