Results 1 to 4 of 4
Is there anyway you can start a process with either a predetermined process ID number or name? Here's what I'm doing, I want to restart a java application that I ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 02-19-2006 #1
- Join Date
- Aug 2005
Process ID control
Is there anyway you can start a process with either a predetermined process ID number or name? Here's what I'm doing, I want to restart a java application that I wrote everyday. When this job runs, it runs under the name java, so I wrote a script that searches for the java process ID name, kills it and then calls the script that starts the application, and put this script into the cron.daily folder. The only problem with this approach is that if any other java program is running over night, it may be killed instead of the app I want to restart. Is there anyway that I can give another name to that instance or a specific ID so that I can just call "kill xyzab" where xyzab is the predetermined PID number that I set? Thanks ahead of time!!
- 02-19-2006 #2
I think it's easiest to have the applet write it's pid to a file, say /var/run/appletname.pid and then check if it's running (additionally you might want to check "/proc/`cat /var/run/appletname.pid`", eg check the cmdline used to start it ( "cat /proc/`cat /var/run/appletname.pid`/cmdline" ).
I don't think it's possible to force a PID for a process, at least not in a "clean" way. IIRC only "init" has a static PID (0), but then again it's not a "real" process.Regards Scienitca (registered user #335819 - http://counter.li.org )
A master is nothing more than a student who knows something of which he can teach to other students.
- 02-19-2006 #3
That's correct, it's not possible, since PIDs are being created on the fly by numerous processes and it's the kernel that determines that information. It won't be bossed around by a mere script! As scientica suggests, best idea and the most common approach to this is to have your script check it's own PID and stuff that info somewhere.
- 02-20-2006 #4
- Join Date
- Aug 2005
I actually used a different approach, I just copied the java executable and renamed it to a unique name. Now when the process runs as that unique name, I can just search for that name is kill, it. Now I have to see why putting that script into the cron.daily folder isn't running that process daily