23

I just upgraded my ubuntu lucid to natty , during the upgrade it replaced most of the running applications with a newer version.

How does this work? (Won't the applications crash?) What will happen to the application if a lib file got upgraded and a running application which is looking for a older lib tries to load it?

6
  • Good question, but probably better asked here: unix.stackexchange.com (I know the URL says Unix but they field Linux questions too!)
    – FrustratedWithFormsDesigner
    May 20, 2011 at 14:24
  • Understanding the replace-while-open functionality of Linux seems like it's still programming (but just barely :)
    – bdonlan
    May 20, 2011 at 14:29
  • 2
    @bdonlan: If you're dynamically loading libraries during the lifetime of your process, you should be very much aware of this, else it may bite you. This is especially important if you're trying to do something unusual, e.g. self-modifying code etc. But yes, it's borderline. May 20, 2011 at 14:35
  • 1
    It's not really relevant to self-modifying code, but it's certainly something someone writing libraries for linux should know, yes. :)
    – bdonlan
    May 20, 2011 at 14:41
  • 1
    @Piskvor, sounds a bit like the multi-stage compilation process for gcc :) But basically only compilers do something like that, and typically you wouldn't upgrade the system while you do it (even if you do, as long as you don't downgrade anything while it's in process, you're fine, since it'll be using its privately compiled copies of anything where it matters)
    – bdonlan
    May 20, 2011 at 15:45

3 Answers 3

32

Linux (and other UNIXes) draws a distinction between the name of a file (the link), the file itself (often identified with the inode), and open handles to the file. When you go to delete a file, you call the unlink() call - this erases the link to the file (you could also use rename() to overwrite it with a different inode). However, if open handles to the file (or other links - files can have multiple hardlinks) remain, the inode remains, and so does the file content, until all links and handles go away.

So running programs using the library or whatever keep a handle to the old version (often implicitly through a memory mapping), so it stays on disk. It just doesn't have a filename anymore, and will be cleaned up when all programs using it shut down (or on the next reboot, during the filesystem check or journal replay).

Further, note that programs expecting the 'old library' will do just fine with newer versions of the library. Linux libraries are assigned a filename ('soname') that reflects the version of the ABI (Application Binary Interface) offered by the library. For example, the C library on my system is libc.so.6. Any program compiled against an older version of libc, but still a version of libc implementing the version 6 ABI, will work fine with it. Really old programs will look for a libc.so.5 or libc.so.4 or something instead; in this case, you'd need to keep the old version around as well - but since the filename is different, this isn't a problem.

0
9

Unlike Windows, you can delete or replace an open file; to give a simplified explanation, new requests for the files open the new file, existing handles use the file that existed when they were created. In other words, in Linux you can have files/file versions that still exist, although there's no longer a pointer to them in the directory structure; those cease existing there is no pointer to them at all (closed and all).

Usually a running app loads the needed libraries up front, so the problem you describe would only happen in very specific timing situations while the package is being installed: the running apps are still using the old version of the library, newly started apps use the new one.

This is used not only in distro upgrades, but happens on every package upgrade (the dist-upgrade just adds a couple more automagic steps to that process).

0

Many Linux processes continue to work after the packages they come from have been upgraded - but some don't. In my experience, KDE never works properly if you upgrade it while it's running. You are likely to experience crashes and/or failures to log out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.