Linux – How to deliberately trigger a “text file busy” error

fileslinux

Very occasionally I encounter "text file busy" error while using my Linux 4.0.4 computer. I read that when the error happens, kernel is preventing modification to a file that is being "used".

So I make sure a file is open (as listed in lsof) and then make modifications to it, everything is fine and "text file busy" error does not happen.

So how do you trigger the an error?

Best Answer

"Text file busy" means a process is trying to modify an executable while it's running ("text" is about a .text segment, not a text file). To trigger it:

$ cp /usr/bin/yes .

$ ./yes >/dev/null &
[1] 27417

$ cat /dev/null >yes
-bash: yes: Text file busy

$ kill %1
[1]+  Terminated              ./yes > /dev/null

$ cat /dev/null >yes

$ ls -s yes
0 yes
Related Question