Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 11 Jul 2016 10:55:35 -0400
From:      Lowell Gilbert <freebsd-questions-local@be-well.ilk.org>
To:        =?iso-8859-1?Q?Sol=E8ne?= <solene@perso.pw>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: cp and mv behaviour on a busy binary file
Message-ID:  <44eg70fcm0.fsf@lowell-desk.lan>
In-Reply-To: <b2d31f0ca12bb3902aa5204e87495138@mail.zplay.eu> (=?iso-8859-1?Q?=22Sol=E8ne=22's?= message of "Mon, 11 Jul 2016 16:41:44 %2B0200")
References:  <b2d31f0ca12bb3902aa5204e87495138@mail.zplay.eu>

next in thread | previous in thread | raw e-mail | index | archive | help
Sol=E8ne <solene@perso.pw> writes:

> I found a not coherent behaviour when overwriting a busy binary and I
> would like an explanation on this.
> When overwriting a busy binary file, without -f flag, cp won't copy
> the file over the executable while mv will ask if you really want to
> overwrite it.
> When using -f, they act the same, the file get overwrited.
>
> Example here :
>
> shell@example : cat test.c
> #include <unistd.h>
>
> int main() {
>         sleep(1000);
>         return 0;
> }
> shell@example : clang test.c
> shell@example : ./a.out &         <- I start the executable
> [1] 83540
> shell@example : touch file
> shell@example : cp file a.out
> cp: a.out: Text file busy         <- cp don't agree
> shell@example : mv file a.out
> override rwxr-xr-x  solene/solene for a.out? (y/n [n]) y <--- mv asks

I believe this behaviour is specifically required by POSIX.
mv(1) must act according to rename(2) and
cp(1) must act according to open(2).



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?44eg70fcm0.fsf>