Find the answer to your Linux question:
Results 1 to 4 of 4
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    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!!

  2. #2
    Linux Enthusiast scientica's Avatar
    Join Date
    Sep 2003
    South- or "Mid-" Sweden
    I think it's easiest to have the applet write it's pid to a file, say /var/run/ and then check if it's running (additionally you might want to check "/proc/`cat /var/run/`", eg check the cmdline used to start it ( "cat /proc/`cat /var/run/`/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 - )
    A master is nothing more than a student who knows something of which he can teach to other students.

  3. #3
    Linux User DThor's Avatar
    Join Date
    Jan 2006
    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.


  4. $spacer_open
  5. #4
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts