help-bash
[Top][All Lists]
Advanced

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

Re: wait until the file is done


From: Marco Ippolito
Subject: Re: wait until the file is done
Date: Mon, 2 Nov 2020 04:24:47 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0

On 31/10/2020 18:41, João Eiras wrote:
I'd solve this use case in bash using flock, if you are in a linux like
environment (on windows, use cygwin).
https://linux.die.net/man/1/flock
e.g.


This type of invocation:

flock -x video.mp4 -c poweroff

The exclusive lock is acquired when no one else has opened the file with
read or write access. That might mean your video editing software closed
the file. Or not. For you to check.
presupposes *collaborative* locking.

The video editing program and the "shutdown watcher" script would both need to try to acquire an exclusive lock on the same pathname, such as:

$ flock -x video.mp4 video-editor --in some_file.mp4 --out video.mp4

$ flock -x video.mp4 sudo poweroff  # Run from another shell

It will not be enough for the video-editor program to open() the file, to contend the lock with its peer, it needs to do so with flock() semantics.

A typical opening mode unaware of this necessity (e.g. O_CREAT | O_TRUNC | O_WRONLY or something similar which you can expect the program to use internally) would not cut it on its own.

Marco Ippolito
maroloccio@gmail.com



reply via email to

[Prev in Thread] Current Thread [Next in Thread]