How does apt-get remove xterm go through? And after it's been uninstalled, xterm doesn't close and continues to function normally.
Is the xterm process cached in RAM whilst it is running?
How does apt-get remove xterm go through? And after it's been uninstalled, xterm doesn't close and continues to function normally.
Is the xterm process cached in RAM whilst it is running?
Not quite. The file is already open by the program. Deleting the file ( and then replacing it with another version ) does not affect the running program because the original file is held open ( though without a name on disk to open it again ) until the program is done with it. Only when all handles to the file are closed are its data blocks on disk released. Until then the open file can be read and written just like normal -- the only change is that nobody else can open it since its name has been removed.
While parts of the program may have already been read into ram when it is deleted, they may still be discarded and re-read later, or new parts of the program that had not previously been executed can still be loaded from the deleted file.
rm -rf / works.....
– heemayl
Jun 15 '15 at 14:45
rm -rf / won't work if you try to run it a second time immediately afterwards ;)
– thomasrutter
Jun 16 '15 at 02:38
lsof output, and I know that is what a 'zombie' file looks like... but is there any way of saving the contents of such a file from disappearing when the last file handle dies?
– Kilian Foth
Jun 16 '15 at 08:34
root might be able to create a name for it (and thus prevent deletion) by using the linkat system call. But executables and libraries are memory mapped, which doesn't require a file handle. I don't know of any way to get a handle on a file which only exists because it is memory mapped. Though executables can be accessed through /proc while they are running, so it's only libraries and other memory mapped files which might be beyond recovery. If you want more details about that, you should ask it as a separate question.
– kasperd
Jun 16 '15 at 18:02
rm -rf / doesn't work and hasn't for many years. See the 2nd line in the Description section of the POSIX specification. That's why GNU rm has the --no-preserve-root option. By itself, /bin/rm -rf / is completely harmless.
– terdon
Jun 17 '15 at 11:25
Is the
xtermprocess cached in RAM whilst it is running?
Exactly. It's similar to the process that allows you to install updates to things while they're running without them crashing. And also why you have to restart services after you update them. Once something is running, its binary is in memory.
If it depends on other files (that aren't in a held "open" state) that are removed or replaced, that might cause issues but for something as discrete as xterm, that isn't an issue.
It is in fact a feature of how computers work: When a program is invoked it is indeed loaded into the memory and it works from there.
A file actually works in the same way. To avoid problems many files in UNIX-ish systems create locks.
The actual riddle is why you can't do such and similar things in Windows.
This feature is actually what allows you to update the whole system, including the programs that are active in your system. ;)
apt-getis uninstallingxterm, and has no idea that it somehow depends on anxtermprocess - so it's about "Why can xterm be uninstalled while running?". Nice question. – Volker Siegel Jun 16 '15 at 02:31