It's OK to replace the executable while the program is running IF you rm
(unlink) it first.
This is not what happens with cp
, so don't use that. Either mv
the file, or, to really be sure, rm
it and then put the new one in the same place. If you are doing this with code in the embedded software, then unlink(2)
is what you want to start with.
Unix kernels know that the inode is still in use, and they will remove the directory entry for the file but they won't release the inode (and the data blocks) until the inode reference count hits zero, and that won't happen while an instance of it is running.
This is probably not an issue with your embedded system, but as a general caution, don't count on this working for networked storage, except when on the server itself.