[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Checken, ob ein (Perl-)Skript schon läuft



On Saturday 21 April 2012, Andre Tann wrote:
> Kurz gesagt, wie macht man es richtig?

$ sudo aptitude install lockfile-progs

Aus der man-Page:

  Locking a file during a lengthy process:

    lockfile-create /some/file
    lockfile-touch /some/file &
    # Save the PID of the lockfile-touch process
    BADGER="$!"
    do-something-important-with /some/file
    kill "${BADGER}"
    lockfile-remove /some/file

Wenn das Skript onehin mit root-Rechten läuft, ist es sinnvoll, das 
Lockfile in /run/lock zu legen, da es dort bei einem Neustart 
automatisch entfernt wird (/run/lock sollte "heutzutage" ein tmpfs 
sein).

do-something-important sollte entweder ein eigenes Skript sein oder es 
sollte durch einen Trap-Handler sichergestellt werden, dass lockfile-
touch beendet wird und lockfile-remove ausgeführt wird.

Michael

-- 
Michael Schuerig
mailto:michael@schuerig.de
http://www.schuerig.de/michael/


Reply to: