From owner-freebsd-questions@FreeBSD.ORG Wed Apr 13 09:24:19 2011 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D9CE0106564A for ; Wed, 13 Apr 2011 09:24:19 +0000 (UTC) (envelope-from bsemene@cyanide-studio.com) Received: from mail.cyanide-studio.com (mail.cyanide-studio.com [62.73.7.64]) by mx1.freebsd.org (Postfix) with ESMTP id 74B2C8FC0A for ; Wed, 13 Apr 2011 09:24:19 +0000 (UTC) Received: from localhost (unknown [10.1.8.14]) by mail.cyanide-studio.com (Postfix) with ESMTP id AFE4717BF440 for ; Wed, 13 Apr 2011 11:08:41 +0200 (CEST) Received: from mail.cyanide-studio.com ([10.1.8.3]) by localhost (mailguard.cyanide-studio.com [10.1.8.14]) (amavisd-maia, port 10024) with ESMTP id 46690-07 for ; Wed, 13 Apr 2011 11:08:41 +0200 (CEST) Received: from [10.1.8.96] (unknown [10.1.8.96]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: bsemene@cyanide-studio.com) by mail.cyanide-studio.com (Postfix) with ESMTP id 8859517BDFFD for ; Wed, 13 Apr 2011 11:08:41 +0200 (CEST) Message-ID: <4DA56819.90503@cyanide-studio.com> Date: Wed, 13 Apr 2011 11:08:41 +0200 From: Bastien Semene User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.2.15) Gecko/20110303 Lightning/1.0b2 Thunderbird/3.1.9 MIME-Version: 1.0 To: freebsd-questions@freebsd.org Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Wed, 13 Apr 2011 11:20:59 +0000 Subject: lockf command X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Apr 2011 09:24:19 -0000 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