title: How to modify a binary while it is running in gdb
body: <p><strong>Edit: The actual problem is with the method by which the binary is updated and isn't due to an issue with gdb. Please see the answer below for details.</strong></p>
  
  <p><em>Original question:</em></p>
  
  <p>Somewhat recently, I can no longer compile a program while gdb is running the program and stopped at a breakpoint. Trying to write to the binary again will result in a "text file busy" error.</p>
  
  <p>This is on Ubuntu 16.04 LTS 64-bit, kernel 4.4.0-75.</p>
  
  <p>I don't think I'm looking for the right thing, as a few searches for "gdb text file busy" or similar isn't yielding any results. The gdb manual specifically mentions this behavior (compile again while running gdb) is supported and indeed I have done this many times previously.</p>
  
  <p>Would appreciate any pointers on what has changed and how to prevent this from happening.</p>