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?

- 4,933
- 16
- 83
- 164
-
2ps auxwww|grep -i 'server' should return all process which has 'server' in them. Otherwise, server may have already stopped. – Usman Saleem Jan 04 '13 at 06:04
-
@Usman saleem thanks this solves my answer. I have One more doubt "nohup server &" is the right command, to run a process backgroung even if i close the terminal? – 2vision2 Jan 04 '13 at 06:07
-
@Mikhail thanks this solves my answer. I have One more doubt "nohup server &" is the right command, to run a process background even if i close the terminal? – 2vision2 Jan 04 '13 at 06:08
-
1Yes it is, you can determine the PID right when you invoke the command: 'nohup server &' followed by 'print $! >> server_pid_file' – Usman Saleem Jan 04 '13 at 06:10
-
1yes, using nohup command means that your 'server' process will discard 'HUP' interrupt which OS sends when you close the terminal. It will also discard 'kill -HUP pid' or 'kill -1 pid'. – Usman Saleem Jan 04 '13 at 06:16
-
You might also want to use `batch` or `at` to run your `server` – Basile Starynkevitch Jan 04 '13 at 06:24
4 Answers
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

- 7,955
- 13
- 49
- 92

- 1,665
- 9
- 18
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!

- 636
- 7
- 18
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.

- 6,212
- 8
- 38
- 69
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

- 7,749
- 11
- 62
- 136
-
I just need to run my executable background? can you give some example? – 2vision2 Jan 04 '13 at 06:10
-
@2vision2 you want to write your program like a linux daemon see http://www.netzmafia.de/skripten/unix/linux-daemon-howto.html – Mikhail Jan 04 '13 at 07:00