LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-17-2015, 07:43 AM   #1
tangchn
LQ Newbie
 
Registered: Jan 2015
Posts: 3

Rep: Reputation: Disabled
Smile How to share the same code segment between two processes using mmaps?


Hi Experts:

I'm new to Linux,recently i was confused with the words as below:

"To achieve sharing,the process A mmaps the executable file of process B into into the virtual address space of process A. As the Linux loader maps the executable files into the process when executing them,the two processes share the memory image of the mapped file"

questions:
1,What are the "executable files",are they ELF files?
2,How to do "mmaps"?if process A and process B share the same code segment, ,where is process A's own code segment?


Thank you in advance.
 
Old 01-17-2015, 08:05 AM   #2
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
1, Yes, typically that would mean ELF files (but it does not necessarily mean ELF files. The concept is broader than the file format).

2, The thing you quoted expressed a common mechanism in a strange way that makes it sound like a weird special case. But I think it is just the common case described strangely:
A process temporarily executes loader code that must be out of the way (elsewhere within the same address space) from the code it is loading. That loader code does the mmaps. After that, in the common case, there is no "A's own code segment" in the sense you are asking. A and B each map the same executable file in the same way. So A's "code segment" would just be the same as B's code segment.
 
Old 01-17-2015, 08:34 AM   #3
tangchn
LQ Newbie
 
Registered: Jan 2015
Posts: 3

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by johnsfine View Post
1, Yes, typically that would mean ELF files (but it does not necessarily mean ELF files. The concept is broader than the file format).

2, The thing you quoted expressed a common mechanism in a strange way that makes it sound like a weird special case. But I think it is just the common case described strangely:
A process temporarily executes loader code that must be out of the way (elsewhere within the same address space) from the code it is loading. That loader code does the mmaps. After that, in the common case, there is no "A's own code segment" in the sense you are asking. A and B each map the same executable file in the same way. So A's "code segment" would just be the same as B's code segment.
Thank you for your reply!

Sorry for my poor expression,What I want to express is :Process_A correspond to code file a.c,where it mmaps b.c's executable fles which corresponding to Process_B into its virtual address space,so Process actually has extra code instructions in its code segment other than Process_B's code,is it right?
And,I'm still confused with the "executable files",can you explain it more detailed?
 
Old 01-17-2015, 01:26 PM   #4
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
OK, now I understand the question, but I don't know the answer.

Mapping a file into the address space is a fairly simple well documented operation. But mapping a second executable is a bit different and I don't actually know how. An executable file has various headers and fixups, so when it is mapped, most of it is directly mapped, but some of it is handled in other ways.


Mapping another process's address space (as a debugger would) is another approach and fairly well documented.

If you give a better idea of what you are trying to accomplish, someone who knows a bit more than I know can probably give you the answer.
 
Old 01-17-2015, 10:50 PM   #5
tangchn
LQ Newbie
 
Registered: Jan 2015
Posts: 3

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by johnsfine View Post
OK, now I understand the question, but I don't know the answer.

Mapping a file into the address space is a fairly simple well documented operation. But mapping a second executable is a bit different and I don't actually know how. An executable file has various headers and fixups, so when it is mapped, most of it is directly mapped, but some of it is handled in other ways.


Mapping another process's address space (as a debugger would) is another approach and fairly well documented.

If you give a better idea of what you are trying to accomplish, someone who knows a bit more than I know can probably give you the answer.
Thank you for your reply.

What i wanna accomplish is like this:
Process_A share the same image of executable file of Process_B,just the executable file of Process_B,Process_A and Process_B have different executable files.

I have some ideas,but i don't know if it's right:
Process_A ->a.c,the executable file is a.out
Process_B ->b.c,the executable file is b.out
I can map b.out into Process_A's virtual address space,or more accurately,maps it into the shared lib area.so, the mapped shared lib area in Process_A and the code segment in Process_B are all point to b.out in the memory,is it right?

Thank you again!
 
  


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
kernel code segment hamedn Linux - Kernel 5 10-17-2011 03:51 PM
Kernel code segment write protection eagle_soaring_1 Linux - Kernel 1 02-28-2011 02:14 PM
whether segment's are specific to each processes Kesavaraj Linux - General 1 08-04-2008 08:42 AM
Write to code segment Earp Programming 4 04-22-2004 01:49 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:05 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