From unknown Sun Jun 15 01:04:52 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#56631 <56631@debbugs.gnu.org> To: bug#56631 <56631@debbugs.gnu.org> Subject: Status: flock does not unlock instantly Reply-To: bug#56631 <56631@debbugs.gnu.org> Date: Sun, 15 Jun 2025 08:04:52 +0000 retitle 56631 flock does not unlock instantly reassign 56631 coreutils submitter 56631 Alexey Kuznetsov severity 56631 normal tag 56631 notabug thanks From debbugs-submit-bounces@debbugs.gnu.org Mon Jul 18 11:50:27 2022 Received: (at submit) by debbugs.gnu.org; 18 Jul 2022 15:50:27 +0000 Received: from localhost ([127.0.0.1]:51875 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oDT0o-0000wx-P7 for submit@debbugs.gnu.org; Mon, 18 Jul 2022 11:50:26 -0400 Received: from lists.gnu.org ([209.51.188.17]:35224) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oDOKw-0007Hk-3v for submit@debbugs.gnu.org; Mon, 18 Jul 2022 06:50:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58474) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDOKv-0003Lp-KH for bug-coreutils@gnu.org; Mon, 18 Jul 2022 06:50:49 -0400 Received: from mail-ej1-x633.google.com ([2a00:1450:4864:20::633]:41748) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oDOKt-0004W1-Vj for bug-coreutils@gnu.org; Mon, 18 Jul 2022 06:50:49 -0400 Received: by mail-ej1-x633.google.com with SMTP id z23so20452171eju.8 for ; Mon, 18 Jul 2022 03:50:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:from:date:message-id:subject:to; bh=xY7kGJ+npr7bf8XT3zK7OE41g+nuo+8HZdNp+qRSiLw=; b=OORQ4sllQdSRRS+WcXVlwHA4IYMcB0LjLQ0djKdst5GD2/pvOAaJ93CHhzKMisyOaf qSRnzdFWnCeK+GAr83AVoNTmkQ23Qbm1DHVf0Bo4Lt+MwOZCIv8y8etXogztjgGefROE kgE41cni+7/l8cvgU9i5FCk95kQHgleso5kGhKTCLeixNRwsn1Nibz0QAWQtJr6P/YQN 0AXKrK+F3+VtSHNueTGGqmSOp2SBl3w5CWOkwnOHt4M6HSj8AiBJTFE7yj6Sp6VOJqXt ioF0a9TxDBDV983JuPslCNyho04NAc7a/OtM8iSlOHeECe60S3CAjUrTh8GMFMqp4awB pr+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=xY7kGJ+npr7bf8XT3zK7OE41g+nuo+8HZdNp+qRSiLw=; b=yZE1ykiSut0woSnJv11Nw3+Hw1AMfwrGZPLGRnVlwwO384S+gA0PHmGjvTt/Ir2dL+ RnQg46bXDbX8dwueNR3bBx87v3dvrSv4BAVvyiaHyJfxEIoHuxPcMcsC9ijbJtkMQ+PZ MuO93bvBo6oCgZMa+WpMUplWnrojJlZL46kJdjpncNiu4yXpVvzo/59SsaeZKfUE6MvR xdotZlZr2MvwZ8cRseT7qDWPqmXRFvSgCW/KufXYbEJDwX5JztDqQqv8Oc1VQ4p0Q3nH RORUjaUn3wcfy848ssg7ARZZ5pNFQ6KKeJYx/nMPK+68CZM88GMd7zmn+kS5yM1VkB7z 2JfQ== X-Gm-Message-State: AJIora/n2d44YXjC6EUU8DsxpDBWb4kq3E99fDSIxeALdsZm/U3VFDot EbrprGyrHxWfu0gEo5Ev5G3FtpnMyQcXpvnZ4pspf30jgegsfQ== X-Google-Smtp-Source: AGRyM1tr/aKhrWzBz9NCU2sgTloi5b1/eBE3mhTU/VZJWUpQ4wIazV8QKC4AcZIP1Mesu5uyWlBx7W6jo/s/LavlFXE= X-Received: by 2002:a17:907:62a6:b0:6ef:8118:d3e2 with SMTP id nd38-20020a17090762a600b006ef8118d3e2mr24508244ejc.605.1658141445654; Mon, 18 Jul 2022 03:50:45 -0700 (PDT) MIME-Version: 1.0 From: Alexey Kuznetsov Date: Mon, 18 Jul 2022 13:50:09 +0300 Message-ID: Subject: flock does not unlock instantly To: bug-coreutils@gnu.org Content-Type: multipart/alternative; boundary="000000000000db0d8105e41223ea" Received-SPF: pass client-ip=2a00:1450:4864:20::633; envelope-from=kuznetsov.alexey@gmail.com; helo=mail-ej1-x633.google.com X-Spam_score_int: -1 X-Spam_score: -0.2 X-Spam_bar: / X-Spam_report: (-0.2 / 5.0 requ) BAYES_20=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Mon, 18 Jul 2022 11:50:21 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) --000000000000db0d8105e41223ea Content-Type: text/plain; charset="UTF-8" Simple bash script: #!/bin/bashset -eexec 7<"$0"flock -n 7sleep 60 Will prevent a second instance from being executed (exits instantly). But if the first instance got killed by 'killall test.sh', the second instance of the script can be executed only after 60 seconds. First instance of the script does report being killed instantly, but still does not let me run the second instance of the script. That makes me think, sleep command not being killed / handled correctly. Here is a work around example, using the following script makes it work correctly: #!/bin/bashset -etrap "kill 0" SIGINT SIGTERMexec 7<"$0"flock -n 7sleep 60 Flock waits until sleep finishes, even when the script holding lock is killed. Is it a bug or feature? -- AK --000000000000db0d8105e41223ea Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Simple bash script:

#!/bin/bash
set -e
exec 7<"$0"
flock -n 7
sleep 60

Will prevent a second instance from being executed (exits i= nstantly). But if the first instance got killed by 'killall test.sh', the seco= nd instance of the script can be executed only after 60 seconds. First instance of the script does report being killed instantly, but still = does not let me run the second instance of the script. That makes me think, sleep command not being killed / handled correctly. He= re is a work around example, using the following script makes it work corre= ctly:

#!/bin/bash
set -e
trap "kill 0" SIG=
INT SIGTERM
exec 7<"$0"
flock -n 7
sleep 60

Flock waits=
 until sleep finishes, even when the script holding lock is killed. Is it a=
 bug or feature?

=
-- AK
--000000000000db0d8105e41223ea-- From debbugs-submit-bounces@debbugs.gnu.org Tue Jul 19 02:15:06 2022 Received: (at 56631) by debbugs.gnu.org; 19 Jul 2022 06:15:06 +0000 Received: from localhost ([127.0.0.1]:52602 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oDgVe-0003Dw-ID for submit@debbugs.gnu.org; Tue, 19 Jul 2022 02:15:06 -0400 Received: from mout.kundenserver.de ([217.72.192.74]:50383) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oDgVb-0003D5-Ky for 56631@debbugs.gnu.org; Tue, 19 Jul 2022 02:15:04 -0400 Received: from [192.168.101.10] ([91.1.218.246]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MvrVJ-1nLa9X22S7-00szX6; Tue, 19 Jul 2022 08:14:56 +0200 Message-ID: Date: Tue, 19 Jul 2022 08:14:55 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: bug#56631: flock does not unlock instantly Content-Language: en-US To: Alexey Kuznetsov , 56631@debbugs.gnu.org References: From: Bernhard Voelker In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K1:skc51fvWhxW7mI81h0hDz9uG2qr3RL+5D7+UT8YQU/FBRFbRIhy vpZVQSYkglMftc40TbMXiILkgsAhqckTdnIcCOgPnDWFXlTxK2K2gEjSvFI/YkJuvCEFWSZ EJOfgTtVn/bKNvzyWHiUWHZe9ljtmjmwPa6Z0rBYRSeRpxvixGkzMTrlIAMahoCOokntHpt pXL7AMhp3tIvqSYRvckJA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:32C8fenYOyw=:YntGuNrJ1fZM/6oOJqlQqV 87lznwLN+r8EtnbDECRlWEJt0Bu5S1sCblm9cWporK5nRsIkhOE+bk5lGYKqylcQd8g/jjUE2 U45gMT/1KmiTxt/ACBeH7QoCp1MReK7LM22QhlJKvijZT/lY+uWlSyh8J/102bbj6HvMKyHhO O7TqYMM1iOIXFIM3FQT1/wiJKMlCnIbf+hAWciglC4CXe4Igido2G2xd4fpOHI49TDNmvz3N3 P/AFZabNKvx5hralDRdqC2SK8GK2/ijJE4a8sunn/T5d4lgcfswgp0anrXAwxiikJli9/x8j3 RniBscMLxfBxNe0jDNuSS7foGoXFdua4V6docmZgzOmAvLOiAhK7NHEkgkke4Yj8rDhSRM+ma pyK4oyF9ybj4jPB18NL3vdX9W74BfIvApVJp73UmtP28KvwzgVCEDvYqx3R3TTeYNzwmmdHIz HeKqalxVr4pz9MO0I2NBgXBU5LdYBRmPRNwl+z/UUA4QEp46wWuoUWKwI5EtL992IdL5SWg/8 ji57RKF/McPfbZp58vaT9JQf8nYnImcNty9z7dWJGXSu4fTExpombOtCET3SBgqhocvNNqf+0 JaKoTo24kTMQoPqcLY5yhoJ4pYVKUweIPmuAFd41A40Movt4qN2TzUobGoLo3tUguR0r5i7u1 eu2qp9pDe9jeb2Z+R18eZDt3qWi1734XU+X9oGsQS0Oq1Qx8tDt4O2pzXwQLBoG2Gy0KskMPu RFLWGVxwkvWR9yt+K/ayYOe8w2E7YrECyyGaAf4SIYTv1tHh65/11UOZKqo= X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 56631 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) tag 56631 notabug close 56631 stop On 7/18/22 12:50, Alexey Kuznetsov wrote: > Simple bash script: > > #!/bin/bashset -eexec 7<"$0"flock -n 7sleep 60 > > Will prevent a second instance from being executed (exits instantly). But > if the first instance got killed by 'killall test.sh', the second instance > of the script can be executed only after 60 seconds. First instance of the > script does report being killed instantly, but still does not let me run > the second instance of the script. That makes me think, sleep command not > being killed / handled correctly. Here is a work around example, using the > following script makes it work correctly: > > #!/bin/bashset -etrap "kill 0" SIGINT SIGTERMexec 7<"$0"flock -n 7sleep 60 > > > Flock waits until sleep finishes, even when the script holding lock is > killed. Is it a bug or feature? First of all, only sleep(1) is relevant here for the coreutils mailing list; flock(1) is part of util-linux, and theoretically also the shell could play into the game. As I see it, flock(1) calls flock(2) - as can be seen by 'strace -vf ./script': [pid 13705] flock(7, LOCK_EX|LOCK_NB) = 0 Looking at `man 2 flock`: Locks created by flock() are preserved across an execve(2). So it's no surprise that sleep(1) inherits and therefore continues to hold the lock until its own termination. As such, I'm closing this bug in the coreutils bug tracker, because sleep(1) does not do anything different from what any other program would do. Of course, the discussion can continue. Have a nice day, Berny From debbugs-submit-bounces@debbugs.gnu.org Tue Jul 19 02:15:48 2022 Received: (at control) by debbugs.gnu.org; 19 Jul 2022 06:15:48 +0000 Received: from localhost ([127.0.0.1]:52605 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oDgWJ-0003F5-TW for submit@debbugs.gnu.org; Tue, 19 Jul 2022 02:15:48 -0400 Received: from mout.kundenserver.de ([217.72.192.74]:56133) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oDgWI-0003Er-O0 for control@debbugs.gnu.org; Tue, 19 Jul 2022 02:15:47 -0400 Received: from [192.168.101.10] ([91.1.218.246]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.183]) with ESMTPSA (Nemesis) id 1Mn2iP-1nm5D00Mop-00k84s for ; Tue, 19 Jul 2022 08:15:41 +0200 Message-ID: <1026b318-4c66-6f6e-51e4-253b2cb7045e@bernhard-voelker.de> Date: Tue, 19 Jul 2022 08:15:40 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Fwd: bug#56631: flock does not unlock instantly Content-Language: en-US References: To: GNU bug control From: Bernhard Voelker In-Reply-To: X-Forwarded-Message-Id: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K1:pylBR0ClqjXPjimsDlbl+NZZIdk203WQOO5rQif40zF5jxihdH+ y7WA46bc6YCQC5RuZ7yqJN7wD8NKACwp33fj1kYYXtwgQ7BUD64gxE/6RUx5OcOGVRCczYr wxyH+F+h09k9B6gEWoBUD5lJZZ6V2+n2jMbnGRV9CJSH+h6MzC/ex7egskmafdQTLj1diTd PXm+dPwOMKlPRkAI/OTVw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:Si/OgbxhcYA=:dupsrJfB8g9YMiCEhkinQa DWjOii3KYn599JhW6ADI/jxVHuYuiLeCWXWJPX+sA/yl3d7Z59LEtLk/GyWHCdhq/bcMvbavn dzaTCbjxHl+E7im72DngA0SbNg6bykE6V7N64ekdLatRBCC7QETq9XPjHfG6f1V72CEJOJVOs zEBtJDexI8age3Bye0Qpks9u4g1f53mM+UdSTiLUBnz1Xk1+TzZ5SzRWKwIyMyj7+Z72/1iY3 b/yHNymYeaKgPATFZHKXjvRq+Eze5BCB2h0Y+J8FSBxzt3ye8zheuNnAXE49I/m2vFfu892ua YuqBpMwgC53DfT3gFNMd7vKlaXC6DxHX0lAasuveGpTbBuo/yM4nEbOWFglyaxwDVVemc+w7+ /uwgdPHuiBVd1G13VGMzyRjRhyLeBchrakGl/zeOZPWrWeIj+ZckBCd71bypMZ+PBUrdpFmuX kCsDJyn0EozgxcbH3xIfovOqujCjwoGugHeJXX6mzDfEELO2Cn5E9al8boNvZ4DlVdyaJwlO8 9BLspq6awSyvYaq0z1G5rtCbnIxxR8blUTACSzu5HSYSTnhtYwHZ9/6SODeGLAX5T7FYWhHzk DF/DyGVFUaETd4t4wfsB3FznQta2pWGWnUykGMVmVdUHMcPdeoopCOSAWlZA8eFdAuk92hfAY jAsTOyTQDbMb4XQQdOn/DPF08qmKNwsye1i3po+IKKw/Ky5fc1JH/aeaUtGsoQ6UzQe4L9Zp4 BImA94r9bVh1sUvUJp0foR1qF0KcuwLn3XoLg3Qmo8c7eo+wKz7ALpnm6do= X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) tag 56631 notabug close 56631 stop On 7/18/22 12:50, Alexey Kuznetsov wrote: > Simple bash script: > > #!/bin/bashset -eexec 7<"$0"flock -n 7sleep 60 > > Will prevent a second instance from being executed (exits instantly). But > if the first instance got killed by 'killall test.sh', the second instance > of the script can be executed only after 60 seconds. First instance of the > script does report being killed instantly, but still does not let me run > the second instance of the script. That makes me think, sleep command not > being killed / handled correctly. Here is a work around example, using the > following script makes it work correctly: > > #!/bin/bashset -etrap "kill 0" SIGINT SIGTERMexec 7<"$0"flock -n 7sleep 60 > > > Flock waits until sleep finishes, even when the script holding lock is > killed. Is it a bug or feature? First of all, only sleep(1) is relevant here for the coreutils mailing list; flock(1) is part of util-linux, and theoretically also the shell could play into the game. As I see it, flock(1) calls flock(2) - as can be seen by 'strace -vf ./script': [pid 13705] flock(7, LOCK_EX|LOCK_NB) = 0 Looking at `man 2 flock`: Locks created by flock() are preserved across an execve(2). So it's no surprise that sleep(1) inherits and therefore continues to hold the lock until its own termination. As such, I'm closing this bug in the coreutils bug tracker, because sleep(1) does not do anything different from what any other program would do. Of course, the discussion can continue. Have a nice day, Berny From unknown Sun Jun 15 01:04:52 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Tue, 16 Aug 2022 11:24:06 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator