Hi,

I'm writing a (very simple) script to avoid concurrent processes to do the same task.

Background:
After a task is done by a service, it synchronizes it with other(s) server(s). I wish that if a synchronization is not done during one or more tasks are completed, not concurrent synchronization processes are launched.


According to the flock manual It seems to be simple:
"If lockf successfully acquires the lock, it returns the exit status produced by command. Otherwise, it returns one of the exit codes defined in sysexits(3), as follows:"


So this script should work:
"#!/bin/sh

flock -k /tmp/lockfile command arguments"


But as far as I tested it doesn't act like this :
- Command #1 : flock -k /tmp/lockfile read input, the shell is waiting for an input.
- Command #2 : flock -k /tmp/lockfile ls -hal /tmp

Launching command #1, then #2.
The command #2 is waiting. When command #1 is finished command #2 is executed.

I wish that if command #2 can't acquire the lock, lockf exits (exit 0 would be nice). If I set -t 1, lockf is quite what I'm waiting for. But I like to do this in a clear way : if it can't acquire the lock it exits, no timeout wait.

Am I misunderstanding something ? What should I change ?

Thanks for your help

--
Bastien Semene
Administrateur Réseau&  Système

Cyanide Studio - FRANCE

_______________________________________________
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"

Reply via email to