Re: sharing of process code segment

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tuesday 09 November 2004 05:42, Mandeep Sandhu wrote:
> Hi all,
>
> i had a doubt regarding a process's code segment in memory.
> suppose i execute 2 instances of an app. prog. (say 2 apache web
> server's from two diff. terminal sessions on the same machine),
> will the code segment of these two processes be shared? I think
> they will be....

Yes.  Assuming you ran the same executable each time and not
copies.

e.g.


$ sleep 10 &
$ sleep 10
Code is shared


$ cp sleep sleep2
$ sleep &
$ sleep2
Code is not shared

> now supposing if i change the binary image of the executable, then
> how does the kernel figure out that the binary has changed and it
> should be reloaded for any new invocations of this program.

Depends on how the new executable is installed.  If the old file is 
unlinked then the new one renamed/copied to the destination name, then 
it will be a new file and the kernel will use the new one for only new 
invocations.  The old file still exists till the programs running it 
exit, there is just no name in the filesystem for it anymore.

If you could do

$ cat newprog > oldprog

you risk crashing any currently running copies of the original 
'oldprog'.  But the Linux kernel appears to be smart enough to not to 
allow you to do that.  Some systems will though.



--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux