shmat fails problem in RedHat Linux 4 - Redhat

This is a discussion on shmat fails problem in RedHat Linux 4 - Redhat ; /* 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: ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: shmat fails problem in RedHat Linux 4

  1. shmat fails problem in RedHat Linux 4

    /*

    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
    #include
    #include

    #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(8) ; }

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

    }


  2. Re: shmat fails problem in RedHat Linux 4

    Hi.

    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


    Rockkon wrote:
    > /*
    >
    > 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
    > #include
    > #include
    >
    > #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(8) ; }
    >
    > printf("SUCCESS\n") ;
    > exit(0) ;
    >
    > }



+ Reply to Thread