Text File Busy
Production Risk
A deployment antipattern — always use atomic rename for binary updates.
ETXTBSY (errno 26) is returned when an attempt is made to write to an executable file that is currently being executed, or to execute a file that is open for writing. The kernel prevents writes to running executables to maintain memory consistency.
- 1Attempting to overwrite an executable binary while a process is running it
- 2Trying to write to a swap file that is in use
- 3Deploying a new binary by overwriting the old one in-place while it is executing
Overwriting a running binary in-place during deployment.
# Attempt to overwrite a running executable: cp new_binary /usr/local/bin/myapp # cp: cannot create regular file '/usr/local/bin/myapp': Text file busy
expected output
cp: error: Text file busy (ETXTBSY)
Fix
Use atomic replacement via rename() instead of overwriting
WHEN When deploying updated binaries
# Write to a temp file first, then rename: cp new_binary /usr/local/bin/myapp.new mv /usr/local/bin/myapp.new /usr/local/bin/myapp # rename() is atomic — the old inode stays valid for running processes
Why this works
rename() updates the directory entry atomically. Existing processes continue executing the old inode while new processes exec the new binary. This is the correct deployment pattern.
✕ Overwrite running binaries in-place
Causes ETXTBSY and can corrupt the running process's memory-mapped executable pages on some systems.
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev