Welcome to Soft32 Linux Forums!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

shmat fails problem in RedHat Linux 4

 
   Soft32 Home -> Linux -> Development RSS
Next:  shmat fails problem in RedHat Linux 4  
Author Message
Rockkon

External


Since: Mar 09, 2006
Posts: 7



(Msg. 1) Posted: Thu Mar 09, 2006 3:35 am
Post subject: shmat fails problem in RedHat Linux 4
Archived from groups: linux>redhat>devel (more info?)

/*

shmtest: Program to exhibit Red Hat Linux 4 shared memory problem.

To exhibit the problem:

Run it once as follows to initialize shared memory:
% shmtest init

Then run it repeatedly as follows to test access to shared memory:
% shmtest

It will sometimes print SUCCESS and sometimes print FAILURE. Why?

Reproducibility:

The problem is reproducible under Red Hat Linux 4, with kernel
version 2.6, both the EL version and the SMP version,
under both the Red Hat Linux Enterprise ES version and the Red Hat
Linux Advanced Server AS version.

The problem occurs with a "default" Red Hat Linux installation as
well as a "complete" installation, with or without patches to the
latest Red Hat Linux 4 version, and with the SELinux component
either enabled or disabled.

The problem DOES NOT occur under Red Hat Linux 3 (kernel version
2.4),
SuSE Linux (kernel version 2.6), nor Debian Linux (kernel version
2.6).

*/

#include <sys/types.h>
#include <sys/ipc.h>
#include <errno.h>

#define KEY1 1111
#define KEY2 2222
#define SIZE1 1000
#define SIZE2 1000

int shmid1, shmid2 ;
char *shmptr1, *shmptr2 ;

main(int argc, char *argv[]) {

errno = 0 ;

/* Initialization: create 2 shared memory partitions. */
if ( argc > 1 ) {

shmid1 = shmget(KEY1, 1000, IPC_CREAT|0666) ;
if ( shmid1 < 0 ) exit(1) ;

shmptr1 = (char *)shmat(shmid1, 0, 0666) ;
if ( (long)shmptr1 == -1 ) exit(2) ;

shmid2 = shmget(KEY2, 1000, IPC_CREAT|0666) ;
if ( shmid2 < 0 ) exit(3) ;

shmptr2 = (char *)shmat(shmid2, 0, 0666) ;
if ( (long)shmptr2 == -1 ) exit(4) ;

/* Save address of 2nd partition in 1st partition. */
*(char **)shmptr1 = shmptr2 ;

printf("Shared memory initialized.\n") ;
exit(0) ;
}

/* Test: locate and access shared memory partitions. */
shmid1 = shmget(KEY1, SIZE1, 0666) ;
if ( shmid1 < 0 ) exit(5) ;

shmptr1 = (char *)shmat(shmid1, 0, 0666) ;
if ( (long)shmptr1 == -1 ) exit(6) ;

/* Fetch address of 2nd partition from 1st partition. */
shmptr2 = *(char **)shmptr1 ;

shmid2 = shmget(KEY2, SIZE2, 0666) ;
if ( shmid2 < 0 ) exit(7) ;

shmptr2 = (char *)shmat(shmid2, shmptr2, 0666) ;
if ( (long)shmptr2 == -1 ) {
printf ("FAILURE, errno = %d\n", errno) ;
exit(Cool ; }

printf("SUCCESS\n") ;
exit(0) ;

}

Thanks for any insight...

Rock
Back to top
Login to vote
Rockkon

External


Since: Mar 09, 2006
Posts: 7



(Msg. 2) Posted: Mon Mar 13, 2006 3:47 am
Post subject: Re: shmat fails problem in RedHat Linux 4 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Thanks. We think we found the problem, we think... There is a
difference in the new gcc compiler. If we compile the program under ES
4 it works without fail. If we compile the program under Red Hat Linux
7.2, the random problem appears.

Rock
Back to top
Login to vote
Christian Ehrhardt

External


Since: Mar 13, 2006
Posts: 1



(Msg. 3) Posted: Mon Mar 13, 2006 11:10 am
Post subject: Re: shmat fails problem in RedHat Linux 4 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hi,

On 2006-03-09, Rockkon <rockkon.RemoveThis@verizon.net> wrote:
> It will sometimes print SUCCESS and sometimes print FAILURE. Why?

if you'd tell us what errno is in this case, we'd be able to make a more
educated guess. Probably the shared memory segment can't be mapped
where you want it to be because there's something else mapped at the same
virtual address.

regards Christian

--
THAT'S ALL FOLKS!
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Regina Rexx for redhat 2.1 - Has anyone sucessfully build Regina Rexx 3.01 for RH Linux 2.1AW running on an IA64 Itanium? I got the package and the...

Dialogic drivers for Redhat 3.0 - Anyone else out there waiting for Dialogic to release drivers for Redhat 3.0? The last release does not work with any....

GARP support in Redhat - Hi All, Dose Redhat support GARP applications ( GMRP and GVRP) on any of its releases. Please let me know. Is there any...

how do i know if it is a redhat kernel distribution? - Is there any macro or any other means by which i can find out that the kernel in my host is from Redhat? From 2.6.12,...

download discountinued redhat-betas? - Hi, does anyone know where i can download discontinued redhat-betas, who have removed from the official server? Greet...

How to build one binary for all Redhat systems? - Hello, My development project's software must run on multiple Redhat-based platforms (All the FedoraCore series, Redha...
       Soft32 Home -> Linux -> Development All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Categories:
 Windows
  Linux
 Mac
 PDA


[ Contact us | Terms of Service/Privacy Policy ]