LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Start a Process with dedicated PID (https://www.linuxquestions.org/questions/linux-newbie-8/start-a-process-with-dedicated-pid-353472/)

murder 08-15-2005 10:37 AM

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.

puffinman 08-15-2005 10:55 AM

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?

rstewart 08-15-2005 12:18 PM

Why can't you use the commandname form of kill instead of the numeric process ID?

saman007uk 08-15-2005 01:15 PM

If you know the command name used to start the game:
Code:

killall command-name

murder 08-15-2005 01:48 PM

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 &

R Tape loading error 08-15-2005 03:49 PM

Quote:

Originally posted by murder
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 &

I would go along the line of what puffinman said, I don't actually think you can reserver PIDs as they are generatedautomatically.

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
# start-stop-daemon --stop --pidfile /var/run/myapp1.pid

# start-stop-daemon --start --pidfile /var/run/myapp2.pid --make-pidfile --background --exec /usr/local/bin/myapp1  option1 option2
# start-stop-daemon --stop --pidfile /var/run/myapp2.pid

replacing myapp1,2 and optionX with your paths and arguments etc...

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.