Ali
Ali

Reputation: 500

Deny write permission during writing to file

chmod -R -w filename will remove write permission but if a program opened a file before denying permission, the program can write to file continually even we remove write permission.

Is there any idea for solving this problem?

Upvotes: 1

Views: 843

Answers (3)

rodrigo
rodrigo

Reputation: 98516

You can use mandatory locking but then the write will not fail with an error, but be blocked indefinitely.

But do not overlook the first paragraph: "Why you should avoid mandatory locking".

Upvotes: 2

TEOUltimus
TEOUltimus

Reputation: 184

Try duplicating it and use the duplicate with a new name instead of the old version. This prevents the program from altering the data you presumably no longer want altered. The obvious solution, though, is to simply kill the program.

Upvotes: 0

frankc
frankc

Reputation: 11483

You can use fuser or lsof to see what processes have the file open and kill them

Upvotes: 0

Related Questions