in reply to File locking; downgrade an exclusive to a shared lock

Use the locked file for essentially nothing other than the Highlander lock. After obtaining the lock, write the most recent pid to a separate logfile that isn't flocked.

The logfile could have the PID written into it and then be closed immediately. No other process will write to your logfile because the semaphore file is locked, assuring "only one." But when you find that you need to kill your process, you can open the log file and inspect it, since it's not actually the file that is getting locked.


Dave

  • Comment on Re: File locking; downgrade an exclusive to a shared lock

Replies are listed 'Best First'.
Re^2: File locking; downgrade an exclusive to a shared lock
by The_Dj (Scribe) on Jul 12, 2013 at 04:30 UTC
    I'd prefer not to create another file if it can be helped...

    I've seen it done where you lock DATA, but that prevents the next instance from running, so it can't log "Run skipped", which is pretty much mandatory for me.

    Any other Ideas?