LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-10-2012, 07:15 AM   #1
duplex
Member
 
Registered: Sep 2012
Posts: 38

Rep: Reputation: Disabled
Question How is it possible tu update a program while it's still running?


The subject says it all. I have always been wondering how it is possible to install a new version of a program while the old version is still running. It cannot be so easy as to just exchange the binaries - the old version would probably crash, have a lot of page faults and bad references, wouldn't it?

Greetings,
d.
 
Old 11-10-2012, 07:31 AM   #2
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
When something is running, it's in memory; you can update or replace the disk file without causing a problem (a file on disk is not a process executing in RAM).

Hope this helps some.
 
Old 11-10-2012, 07:40 AM   #3
duplex
Member
 
Registered: Sep 2012
Posts: 38

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by tronayne View Post
When something is running, it's in memory; you can update or replace the disk file without causing a problem (a file on disk is not a process executing in RAM).
Hmmm, I always thought that Linux does "demand paging", that is, it only loads the parts or chunks of the program into physical memory pages when they are needed (in opposition to Windows NT, e.g., which wants to have the whole binary in physical memory before it starts executing).

So when you exchange the binary (the disk file), the new parts (chunks, pages) will not fit with the ones already in memory. Where is my reasoning wrong here?

Greetings,
d.
 
Old 11-10-2012, 03:33 PM   #4
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
So think of this -- what happens when you have a running system and install updates or patches? Works fine, right? You can compile and install a new kernel on a running box (then reboot and the new kernel is available). You can install an upgrade of, oh, glibc, say, and everything keeps working?

I stop something like Firefox, Thunderbird and other applications before installing a new version but I've never had a problem with upgrades or patches.

So, I dunno, seems to have worked for me lo these many years.
 
Old 11-11-2012, 10:29 AM   #5
duplex
Member
 
Registered: Sep 2012
Posts: 38

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by tronayne View Post
You can compile and install a new kernel on a running box (then reboot and the new kernel is available).
You name it: You have to reboot!

Quote:
You can install an upgrade of, oh, glibc, say, and everything keeps working?
This is exactly what I doubt or what I do not understand. If libc (after 40 years or so) suddenly changes the semantics of something so fundamental as gets() or printf(), I ask myself whether there are now 2 shared libraries in memory, one for the programs already running and using the old libc, one for the ones to be newly started.

D.
 
Old 11-13-2012, 10:58 AM   #6
segmentation_fault
Member
 
Registered: Sep 2008
Location: Ioannina, Greece
Distribution: Gentoo
Posts: 332

Rep: Reputation: 55
I have been upgrading firefox and thunderbird while they are running with no problem at all. The running process is from the old binary. If you restart it, you get the new. That's also the case with the kernel. You need to reboot to use the new kernel, but your system keeps running fine with the old one loaded into memory. I have also upgraded glibc and the system never complained. All this on Gentoo. Once I tried upgrading glibc on Slack, and I totally screwed my system, so you need to follow the proper instructions when upgrading system libs.
Now, if there was a major change in a lib's API, such as a major change in gets() or whatever system call, all the binaries using the old one should be re-written and re-compiled to use the new one.
 
Old 11-13-2012, 11:06 AM   #7
snowday
Senior Member
 
Registered: Feb 2009
Posts: 4,667

Rep: Reputation: 1411Reputation: 1411Reputation: 1411Reputation: 1411Reputation: 1411Reputation: 1411Reputation: 1411Reputation: 1411Reputation: 1411Reputation: 1411
If you are concerned about it then you can upgrade outside of X as recommended by aptosid:

http://manual.aptosid.com/en/sys-admin-apt-en.htm

While I do not always practice this myself, it certainly seems sensible.
 
Old 11-13-2012, 02:08 PM   #8
duplex
Member
 
Registered: Sep 2012
Posts: 38

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by segmentation_fault View Post
I have been upgrading firefox and thunderbird while they are running with no problem at all. The running process is from the old binary.
Yes, but the old binary is (probably) not completely in memory. That's what I cannot understand. I just can imagine a scheme such as the following:

1) There is a startup script S for Firefox, which never changes. This is what is run whenever you start Firefox.
2) An update first copies a new version A' of the real binary into some fixed location
3) On every (re-)start, S first looks into this location to see whether there is a new version A', and copies it over the old version A.
4) S starts A.

BTW, under Windows, you always have to close the program that you are upgrading. (?)


Quote:
I have also upgraded glibc and the system never complained. All this on Gentoo.
I have no explanation how this is possible.

Quote:
Now, if there was a major change in a lib's API, such as a major change in gets() or whatever system call, all the binaries using the old one should be re-written and re-compiled to use the new one.
Yes, that's clear, but another story.

Greetings,
Duplex
 
Old 11-13-2012, 05:49 PM   #9
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
An important concept in Linux file systems is there actually is no system call to remove a file. What you have is the unlink() system call to remove a link to a file from a directory. The file is not actually removed from disk until the link count goes to zero and no running process still has the file open.

When you install a new version of, say, /bin/cat, the new file is first written to a temporary name, then the old file is unlinked and the temporary file renamed to /bin/cat. The reason this works is that the old file still exists on disk (with no link from any directory) as long as any running process has a reference to it. So, any currently running /bin/cat process continues to use the old data blocks, and any newly started /bin/cat will run the new version. The same thing holds for library files. When you update glibc, all the old files are unlinked and replaced by new versions, while all currently running processes continue to use the old (unlinked) glibc files. Only when the reference count goes to zero will the kernel return the data blocks used by those files to the free list.

This is why a reboot is recommended for any update of things like glibc that are used by many running processes. You will still have processes using the old version (and that old glibc will still occupy space on the disk) until every one of those processes has been restarted.

The reason Windows doesn't do this is that its file system is unable to keep an unlinked file's contents available to processes that are currently using it, and so you cannot unlink a file that is currently in use.

Incidentally, programs that open new libraries and plugins by name during execution will get the new version, and that can (and sometimes does) cause the process to crash.
 
1 members found this post helpful.
Old 11-13-2012, 11:01 PM   #10
replica9000
Senior Member
 
Registered: Jul 2006
Distribution: Debian Unstable
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 260Reputation: 260Reputation: 260
I also like the fact that you can simply restart a service after upgrade, such as xorg, without restarting the entire machine. The only thing you can't avoid a reboot is with running a new kernel, although kexec will cut down the reboot time.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Script to start a program either not running or kill if running avataratar Linux - Newbie 1 03-29-2012 02:45 AM
Running an Interactive Program From Within a Program BrandonShw Programming 4 11-23-2011 12:51 PM
how do I update a program? joseph2020 Linux - Software 7 05-16-2009 12:11 AM
Running program from terminal with & does nothing, program stops DittoAlex Linux - General 1 10-05-2007 01:35 AM
How do I update a program? MOZ Linux - Software 1 01-21-2002 01:35 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration