ETXTBSY
Linux / POSIXERRORNotableFile SystemHIGH confidence

Text File Busy

Production Risk

A deployment antipattern — always use atomic rename for binary updates.

What this means

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.

Why it happens
  1. 1Attempting to overwrite an executable binary while a process is running it
  2. 2Trying to write to a swap file that is in use
  3. 3Deploying a new binary by overwriting the old one in-place while it is executing
How to reproduce

Overwriting a running binary in-place during deployment.

trigger — this will error
trigger — this will error
# 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

Use atomic replacement via rename() instead of overwriting
# 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.

What not to do

Overwrite running binaries in-place

Causes ETXTBSY and can corrupt the running process's memory-mapped executable pages on some systems.

Sources
Official documentation ↗

Linux Programmer Manual open(2)

rename(2)

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Linux / POSIX errors