View Issue Details

IDProjectCategoryView StatusLast Update
00019301003.1(2016/18)/Issue7+TC2Shell and Utilitiespublic2025-06-19 16:59
Reportersteffen Assigned To 
PrioritynormalSeverityEditorialTypeEnhancement Request
Status NewResolutionOpen 
NameYour Name Here
Organization
User Reference
Section(section number or name, can be interface name)
Page Number(page or range of pages)
Line Number(Line or range of lines)
Interp Status
Final Accepted Text
Summary0001930: Add flock(1) utility to manage locks from shell scripts
DescriptionI myself make extensive use of this utility in my system management etc shell scripts.

It must be said it is not widely available -- as flock(1).
Linux has it, NetBSD has it; semantics are somewhat shared
FreeBSD and DragonFly have lockf(1), which is quite similar, but use lockf(3) (i think).
Busybox (Linux toolbox) has it, with some minimized interface, currently without -w (wait for lock).

If POSIX could standardize this it would be great, and if it would include F_OFD_SETL locks when doing so, that would be even better!
Desired ActionAdd flock(1). I will paste the NetBSD manual below, which is BSD 2-clause licensed.

NAME
     flock – Provide locking API for shell scripts

SYNOPSIS
     flock [-dnosvx] [-w timeout] file|directory command [args ...]
     flock [-dnosvx] [-w timeout] file|directory -c command
     flock [-dnsuvx] [-w timeout] number

DESCRIPTION
     The flock utility provides flock(2) access to the command line or
     scripts. The first two forms lock the specified file or directory while
     the provided command is executed. If the path does not exist, then a
     file of that name is created with mode 0600.

     The third form can use an arbitrary file descriptor number that is
     provided from a shell script for example:

           (
                   flock -s 100
                   # commands to be executed under the lock
           ) 100> /path/to/lockfile

     The following options are available:

     -c command Pass a command to a the shell.

     -d, --debug
                 Provide debugging output.

     -n, --nb, --nonblock
                 Don't block and fail immediately if the lock could not be
                 obtained.

     -o, --close
                 Close the file before executing the command. This is useful
                 if the child forks and should not be holding the lock.

     -s, --shared
                 Obtain a shared lock.

     -u, --unlock
                 Unlock an existing lock. This is available only for a file
                 descriptor.

     -v, --verbose
                 On error print an explanation of the failure.

     -w, --wait, --timeout seconds
                 Fail if the lock could not be obtained after seconds.

     -x, --exclusive
         EXIT STATUS
     The flock utility exits 0 on success, and >0 if an error occurs.

SEE ALSO
     shlock(1), flock(2)
        Obtain an exclusive lock. This is the default.
TagsNo tags attached.

Activities

There are no notes attached to this issue.

Issue History

Date Modified Username Field Change
2025-06-19 16:59 steffen New Issue