Start a Process with dedicated PID
is there a way to start a process with a dedicated id? what im trying to do is be able to kill a gameserver and relaunch it but without having to go in and do a ps -x to get the PID and then kill it. I was wondering if there was a way i could just keep the same id that way i could just kill it from webmin real quick and easy.
|
There are lots of programs that keep a pid file. Look in /var/run and you'll likely see many files with the pid extension. These are simply plaintext files that contain the process id. You can then run things like "kill -HUP `cat /var/run/some.pid`" to restart the program.
If the gameserver doesn't have the option to create this file (check the docs), you could write a small daemon that records its own pid and also knows the pid of the game server (it will have to fork and exec the server itself, most likely), so you can signal it to do the restart. I don't think it's wise to try to reserve pids; what do you do if the pid you want is already taken? |
Why can't you use the commandname form of kill instead of the numeric process ID?
|
If you know the command name used to start the game:
Code:
killall command-name |
here is the command i am using only in a script i have 2 instances of this command running is there a way to kill them individually
Code:
./cod_lnxded +set net_ip 209.165.244.162 +set net_port 28960 + set ttycon 0 +set dedicated 2 +exec server.cfg +set fs_homepath /home/murder/cod/codsd +set fs_basepath /home/murder/cod/codsdinstall & |
Quote:
If your running Debian, you could use the start-stop-daemon command just like the init scripts, this would actually create the pid reference files for you. e.g. Code:
# start-stop-daemon --start --pidfile /var/run/myapp1.pid --make-pidfile --background --exec /usr/local/bin/myapp1 option1 option2 or you could expand your current script to create them after the server is called, maybe by using the $$ or $! environment variables (if bash) |
All times are GMT -5. The time now is 12:25 AM. |