In the operating system Linux, you are working with many components. You might get various errors while working, in which, the error device or resource busy is one of the most common ones. This error refers to the situation when you cannot delete some directors when a resource or device is busy. Alternatively, this error also might happen when you try to move, copy or delete a file of data. This post would like to give you guidance on solving this issue.
1. Using lsof for Finding the Open File in a Linux Directory
Everything in the Linux operating system is considered as files and maintained as folders. Hence, a file plays an important role in Linux. While working in this system, there might have various files or folders simultaneously used, some of which you can see and some you cannot.
Isol is a command for “List of Open File”. This command will provide the open files. Primarily, it will give information for showing out which files are opened based on which process. Not only regular files are listed but also a directory and others.
Therefore, lsof is the first method to resolve the error device or resource busy by taking its functionality to find the open file in the Linux directory.
$ lsof +D /path
chrome 39483 39488 GpuMemory user mem REG 8,5 285840 11410830 /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.12.0 chrome 39483 39488 GpuMemory user mem REG 8,5 678064 11411469 /usr/lib/x86_64-linux-gnu/libpixman-1.so.0.38.4 chrome 39483 39488 GpuMemory user mem REG 8,5 1065824 11411080 /usr/lib/x86_64-linux-gnu/libharfbuzz.so.0.20600.4 chrome 39483 39488 GpuMemory user mem REG 8,5 41152 11411707 /usr/lib/x86_64-linux-gnu/libthai.so.0.3.1 chrome 39483 39488 GpuMemory user mem REG 8,5 112960 11410855 /usr/lib/x86_64-linux-gnu/libfribidi.so.0.4.0 chrome 39483 39488 GpuMemory user mem REG 8,5 85448 11411836 /usr/lib/x86_64-linux-gnu/libwayland-server.so.0.1.0 chrome 39483 39488 GpuMemory user mem REG 8,5 39448 11410444 /usr/lib/x86_64-linux-gnu/libXrender.so.1.3.0 chrome 39483 39488 GpuMemory user mem REG 8,5 26800 11410422 /usr/lib/x86_64-linux-gnu/libXdmcp.so.6.0.0 chrome 39483 39488 GpuMemory user mem REG 8,5 18688 11410411 /usr/lib/x86_64-linux-gnu/libXau.so.6.0.0 chrome 39483 39488 GpuMemory user mem REG 8,5 709496 11409861 /usr/lib/x86_64-linux-gnu/libsystemd.so.0.28.0 chrome 39483 39488 GpuMemory user mem REG 8,5 101320 11411551 /usr/lib/x86_64-linux-gnu/libresolv-2.31.so
After this command is run, your trouble will be resolved through the under/path file system. Hence, you should apply this command for large directories.
Those programs can be exited or killed by using the command kill after you find which process contains the open files.
2. Resolving the Error Device or Resource Busy by Using Alternative Method on Linux
You can use the below command under that directory and see what will happen.
. .. destination source
Look at the file contents with vi.
$ vi destination source
" ============================================================================ " Netrw Directory Listing (netrw v165) " /home/user/user/aven/destination " Sorted by name " Sort sequence: [\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$ " Quick Help: <F1>:help -:go up dir D:delete R:rename s:sort-by x:special " ============================================================================== ../ ./ thanosdir/ thanosdir2/ thanosdir4/ thanos.txt thanos1.txt thanos2.txt ~
You will see that the data contained in the 8th column was disarrayed. Therefore, the ps command was used. This command is commonly utilized for listing the running process and its PIDs accompanying other information based on different options.
If you are curious about what PID is, then keep on reading. Each process in Linux system will be assigned a process ID as known as PID. This refers to the way the system indicates and monitors the processes.
Any communication about the process happening between the operating system and the user during the operation will contain translating between PIDs and process names. This is why the PID will always be contained by these utilities in the output.
$ ps -ef | grep thanos1.txt
user 44317 38941 0 22:10 pts/0 00:00:00 grep --color=auto thanos1.txt
As being said, the PID is contained in the output. Hence, we can use the command kill PID for killing that process.
In conclusion, this blog has provided you with guidance on resolving the error device or resource busy on Linux. Hope that the coding example are are easy to understand so you can practice it efficiently. If you are curious about other errors on computer systems, you can visit other posts on our website!