What does the linux command rm do?
It accepts a file name as an argument and deletes that file from the file system.
What happens if the file name is rm itself?
It deletes the file without any error.
How?
Linux Kernel maintains the number of processes which have currently kept the file open. A file is removed from the disk only if the number of processes that have kept the file open and the number of hard links to the file are both zero.
So when rm command deletes the file it simply removes the hard link of the file to the disk area. But since rm process is executing, the rm file is open. When the rm process exits the kernel notices that there is no process holding the disk area and hence removes the file from the disk.
You can try this out. But don't do it with the rm file in the /bin directory. Instead make a copy of rm in some other directory and try
'./rm ./rm' from that directory.
No comments:
Post a Comment