Find the answer to your Linux question:
Results 1 to 3 of 3
I am running an executable file that needs to be monitored vi the program monit. The executable I am running does not create a PID file and monit uses PID ...
  1. #1
    Just Joined!
    Join Date
    Mar 2006
    Posts
    10

    PID files

    I am running an executable file that needs to be monitored vi the program monit. The executable I am running does not create a PID file and monit uses PID files to stop and start services. Is there a way to force an executable to run with a PID file of my choice?

  2. #2
    Linux Newbie jnojr's Avatar
    Join Date
    Sep 2007
    Posts
    105
    No.

    What you could do, though, is run your program with something like:

    # foo && ps -C foo | cut -d" " -f 1 > /var/run/foo

  3. #3
    Linux Engineer
    Join Date
    Nov 2004
    Location
    Ft. Polk, LA
    Posts
    796
    What do you mean by it uses a pid file to start and stop services? A pid file doesn't start or stop anything, it's just a file with a number in it. It is kept in /var/run and is called by the name of the executable, plus a .pid extension. All it contains is the process id of the executable, which is the same thing ps will tell you when it lists it. Generally, programs which use pid files create one when they start, remove it when they quit, this way if you try running it again it will see that there's already a copy running by seeing the pid file and won't start a second copy as long as the pid file is there. If the program doesn't create the nessecary pid file, then without hacking it into the code, it's quite trivial to write a wrapper script around the program to create a pid file when it starts, delete it when it exits, and check that no pid file exists before allowing it to start. Check out the Advanced Bash Scripting Guide for more info about the scripting stuff.

Posting Permissions

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