LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 08-15-2005, 11:37 AM   #1
murder
LQ Newbie
 
Registered: Aug 2005
Posts: 29

Rep: Reputation: 15
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.
 
Old 08-15-2005, 11:55 AM   #2
puffinman
Member
 
Registered: Jan 2005
Location: Atlanta, GA
Distribution: Gentoo, Slackware
Posts: 217

Rep: Reputation: 30
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?
 
Old 08-15-2005, 01:18 PM   #3
rstewart
Member
 
Registered: Feb 2005
Location: Sunnyvale, CA
Distribution: Ubuntu
Posts: 205

Rep: Reputation: 38
Why can't you use the commandname form of kill instead of the numeric process ID?
 
Old 08-15-2005, 02:15 PM   #4
saman007uk
Member
 
Registered: Dec 2003
Location: ~root
Distribution: Debian
Posts: 363

Rep: Reputation: 32
If you know the command name used to start the game:
Code:
killall command-name
 
Old 08-15-2005, 02:48 PM   #5
murder
LQ Newbie
 
Registered: Aug 2005
Posts: 29

Original Poster
Rep: Reputation: 15
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 &
 
Old 08-15-2005, 04:49 PM   #6
R Tape loading error
LQ Newbie
 
Registered: Aug 2005
Location: Worksop, UK
Distribution: Debian, there can be only one !
Posts: 3

Rep: Reputation: 0
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)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting pid of a process!! vishamr2000 Programming 31 09-09-2005 09:46 PM
how to get more process' info according to its PID? iclinux Programming 1 02-05-2005 06:30 AM
How can I create a pid file from a backgournd process that I start? Hackiller Linux - General 3 05-12-2004 03:37 PM
Getting PID of running process in C/C++ laikos Programming 9 03-15-2004 04:33 AM
Get Next PID of Process Tree zer0python Programming 7 11-26-2003 12:56 PM


All times are GMT -5. The time now is 05:02 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration