From owner-freebsd-questions@freebsd.org Mon Jul 11 14:55:52 2016 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 30380B8F938 for ; Mon, 11 Jul 2016 14:55:52 +0000 (UTC) (envelope-from freebsd-questions-local@be-well.ilk.org) Received: from be-well.ilk.org (be-well.ilk.org [23.30.133.173]) by mx1.freebsd.org (Postfix) with ESMTP id 0CF501DF0 for ; Mon, 11 Jul 2016 14:55:51 +0000 (UTC) (envelope-from freebsd-questions-local@be-well.ilk.org) Received: from lowell-desk.lan (router.lan [172.30.250.2]) by be-well.ilk.org (Postfix) with ESMTP id 00F9A33C1E; Mon, 11 Jul 2016 10:55:38 -0400 (EDT) Received: by lowell-desk.lan (Postfix, from userid 1147) id 4071939819; Mon, 11 Jul 2016 10:55:36 -0400 (EDT) From: Lowell Gilbert To: =?iso-8859-1?Q?Sol=E8ne?= Cc: freebsd-questions@freebsd.org Subject: Re: cp and mv behaviour on a busy binary file References: Reply-To: freebsd-questions@freebsd.org Date: Mon, 11 Jul 2016 10:55:35 -0400 In-Reply-To: (=?iso-8859-1?Q?=22Sol=E8ne=22's?= message of "Mon, 11 Jul 2016 16:41:44 +0200") Message-ID: <44eg70fcm0.fsf@lowell-desk.lan> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Jul 2016 14:55:52 -0000 Sol=E8ne 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 > > 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).