Discussion:
cp and mv behaviour on a busy binary file
(too old to reply)
Solène
2016-07-11 14:41:44 UTC
Permalink
Hello,

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 :

***@example : cat test.c
#include <unistd.h>

int main() {
sleep(1000);
return 0;
}
***@example : clang test.c
***@example : ./a.out & <- I start the executable
[1] 83540
***@example : touch file
***@example : cp file a.out
cp: a.out: Text file busy <- cp don't agree
***@example : mv file a.out
override rwxr-xr-x solene/solene for a.out? (y/n [n]) y <--- mv asks


Kind regards
Lowell Gilbert
2016-07-11 14:55:35 UTC
Permalink
Post by Solène
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.
#include <unistd.h>
int main() {
sleep(1000);
return 0;
}
[1] 83540
cp: a.out: Text file busy <- cp don't agree
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).

Loading...