LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-19-2006, 10:25 AM   #1
nuxrl
Member
 
Registered: Jun 2006
Location: NY, USA
Distribution: Slackware, Arch
Posts: 176

Rep: Reputation: 35
shmat()


If two processes attach to the same shared memory segment, is it possible to make shmat() attach the shared memory segment to the same local space address in both processes? In other words, if shmat(shm_id, 0, flags) returns 0xc04ab000 in proc1, I would like shmat() returns the same address in proc2, which is 0xc04ab000.
 
Old 09-19-2006, 10:32 AM   #2
nuxrl
Member
 
Registered: Jun 2006
Location: NY, USA
Distribution: Slackware, Arch
Posts: 176

Original Poster
Rep: Reputation: 35
I could pass 0xc04ab000 as the second parameter when calling shmat(), but since it's from proc1, I have to get it using some sort of IPC. HP-UX returns the same local space address if processes attach to the same segment. Looks like it's not guaranteed in Linux.
 
Old 09-20-2006, 02:12 AM   #3
pankaj99
Member
 
Registered: Mar 2006
Location: India
Distribution: Fedora
Posts: 47

Rep: Reputation: 15
To get the same shared memory between two process ,I
think you have to give the same shmid while calling shmat().
So you don't have to pass the address ,you have to pass
the shmid.


Do the following:
1)process1 gets the shared memory by shmget(),
returning a shmid.

2)process1 attaches to the shared memory by shmat() usingthe shmid returned previously.

3)pass the shmid to process2.

4)process2 attaches to the shared memory using the same shmid.

now you are free to use the shared memory as you wish.
then both process should detach themselves and one should release the shared memory.


PS:let us know how you did it
 
Old 09-20-2006, 05:41 AM   #4
nuxrl
Member
 
Registered: Jun 2006
Location: NY, USA
Distribution: Slackware, Arch
Posts: 176

Original Poster
Rep: Reputation: 35
It should work in Unix. In Linux, no.
 
Old 09-20-2006, 12:34 PM   #5
pankaj99
Member
 
Registered: Mar 2006
Location: India
Distribution: Fedora
Posts: 47

Rep: Reputation: 15
are you forking the processes?
 
Old 09-20-2006, 01:20 PM   #6
nuxrl
Member
 
Registered: Jun 2006
Location: NY, USA
Distribution: Slackware, Arch
Posts: 176

Original Poster
Rep: Reputation: 35
No, I am not.
 
  


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
problem in attaching memory more then 256 thorugh shmat function shashwat.gupta Programming 2 05-16-2006 12:05 AM
shmat "invalid argument" snowing Programming 0 03-26-2006 09:03 PM
shmat vulnerability in *BSD chort *BSD 0 02-07-2004 09:29 PM
shmat error Fatal_3rr0r Linux - Hardware 1 06-13-2003 02:21 AM
Difference between unix/linux shmat rburge Linux - Software 0 03-19-2003 09:13 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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