What generates the “text file busy” message in Unix?

前端 未结 12 1947
渐次进展
渐次进展 2020-12-04 06:38

What operation generates the error \"text file busy\"? I am unable to tell exactly.

I think it is related to the fact that I\'m creating a temporary python script (u

相关标签:
12条回答
  • 2020-12-04 06:55

    It's a while since I've seen that message, but it used to be prevalent in System V R3 or thereabouts a good couple of decades ago. Back then, it meant that you could not change a program executable while it was running.

    For example, I was building a make workalike called rmk, and after a while it was self-maintaining. I would run the development version and have it build a new version. To get it to work, it was necessary to use the workaround:

    gcc -g -Wall -o rmk1 main.o -L. -lrmk -L/Users/jleffler/lib/64 -ljl
    if [ -f rmk ] ; then mv rmk rmk2 ; else true; fi ; mv rmk1 rmk
    

    So, to avoid problems with the 'text file busy', the build created a new file rmk1, then moved the old rmk to rmk2 (rename wasn't a problem; unlink was), and then moved the newly built rmk1 to rmk.

    I haven't seen the error on a modern system in quite a while...but I don't all that often have programs rebuilding themselves.

    0 讨论(0)
  • 2020-12-04 06:58

    This occurs when you try and write to a file that is currently being executed by the kernel, or execute a file that is currently open for writing.

    Source: http://wiki.wlug.org.nz/ETXTBSY

    0 讨论(0)
  • 2020-12-04 07:00

    I came across this in PHP when using fopen() on a file and then trying to unlink() it before using fclose() on it.

    No good:

    $handle = fopen('file.txt');
    // do something
    unlink('file.txt');
    

    Good:

    $handle = fopen('file.txt');
    // do something
    fclose($handle);
    unlink('file.txt');
    
    0 讨论(0)
  • 2020-12-04 07:01

    One of my experience:

    I always change the default keyboard shortcut of Chrome through reverse engineering. After modification, I forgot to close Chrome and ran the following:

    sudo cp chrome /opt/google/chrome/chrome
    cp: cannot create regular file '/opt/google/chrome/chrome': Text file busy
    

    Using strace, you can find the more details:

    sudo strace cp ./chrome /opt/google/chrome/chrome 2>&1 |grep 'Text file busy'
    open("/opt/google/chrome/chrome", O_WRONLY|O_TRUNC) = -1 ETXTBSY (Text file busy)
    
    0 讨论(0)
  • 2020-12-04 07:02

    If trying to build phpredis on a Linux box you might need to give it time to complete modifying the file permissions, with a sleep command, before running the file:

    chmod a+x /usr/bin/php/scripts/phpize \
      && sleep 1 \
      && /usr/bin/php/scripts/phpize
    
    0 讨论(0)
  • 2020-12-04 07:03
    root@h1:bin[0]# mount h2:/ /x             
    root@h1:bin[0]# cp /usr/bin/cat /x/usr/local/bin/
    root@h1:bin[0]# umount /x
    ...
    root@h2:~[0]# /usr/local/bin/cat 
    -bash: /usr/local/bin/cat: Text file busy
    root@h2:~[126]#
    
    ubuntu 20.04, 5.4.0-40-generic
    nfsd problem, after reboot ok
    
    0 讨论(0)
提交回复
热议问题