LINUX shm_open::Bad file descriptor / (SGI Runs Well)

From: Christopher M. Lusardi (clusardi2k_at_aol.com)
Date: 11/17/04


Date: 17 Nov 2004 12:45:48 -0800

Hello,

  Does anyone know why I get the message on the subject line when I
execute the following code on Linux and/or how to fix it?

  The routine appears to run nicely on SGI!

Note: The program compiles on Linux with the -lrt option.

Thank you,
Christopher Lusardi

------------------------- Routine ---------------------------

#include <fcntl.h>
#include <sys/mman.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

int initialize ()
{
     int my_size;
     void *my_ptr;
     int my_memory;

     my_size = 0x100000; /* number of bytes */

     my_memory = shm_open ("/var/tmp/my_memory", (O_RDWR | O_CREAT),
      (S_IRWXO | S_IRWXG | S_IRWXU)); /* r/w others group users */

     chmod ("/var/tmp/my_memory",(S_IRWXG | S_IRWXU)); /* g/u */

     ftruncate (my_memory,my_size); /* Truncate CREATE file! */
     
     if ( my_memory == -1 )
     {
       perror (shm_open:");
       exit (1);
     }

   ptr = (void *) mmap (NULL,my_size,(PROT_READ | PROT_WRITE),
                        (MAP_SHARED),my_memory,0); /* memory */

   if ( ptr == MAP_FAILED )
   {
     perror ("mmap");
     exit (1);
   }

   if ( close (shmd) )
   {
     perror ("close");
     exit (1);
   }

   return (ptr);
}

/********************* Caller Routine **********************/

int main ()
{
  (void) initialize (); /* check stubbed routine */
}



Relevant Pages

  • LINUX shm_open::Bad file descriptor / (SGI Runs Well)
    ... execute the following code on Linux and/or how to fix it? ... The routine appears to run nicely on SGI! ... The program compiles on Linux with the -lrt option. ...
    (comp.sys.sgi.misc)
  • Re: Home brew Z80 CP/M computer
    ... My system was broken so badly, neither Dell nor Microsoft could fix it. ... I must have spent two weeks on the phone with tech support people, trying to fix the problem. ... A few years spent running big apps on a Linux box showed me that their apps fail at just about the same frequency as Windoze. ... Unfortunately, it seems that the complexity of both Unix and Linux has grown greatly since the "Good Old Days," As I mentioned, my experience with Linux has been that it's buggy, too. ...
    (comp.os.cpm)
  • Re: PATCH: cdrecord: avoiding scsi device numbering for ide devices
    ... I am able to decide myself what is a bug and what ... Looks like a typical answer from somebody who's thoughts are limited to a Linux ... >there's a Linux kernel bug, people should be pointed at linux-kernel and ... As it takes only 5 minutes to fix the include ...
    (Linux-Kernel)
  • Re: Home brew Z80 CP/M computer
    ... I must have spent two weeks on the phone with tech support people, trying to fix the problem. ... About a week later, some software app vendor sent down their own "Upgrade," which broke one of my major apps. ... A few years spent running big apps on a Linux box showed me that their apps fail at just about the same frequency as Windoze. ... Unfortunately, it seems that the complexity of both Unix and Linux has grown greatly since the "Good Old Days," As I mentioned, my experience with Linux has been that it's buggy, too. ...
    (comp.os.cpm)
  • [ANNOUNCE] kvm-66 release
    ... Windows and Linux guests are supported. ... fix userspace compilation failure without kernel pit ... stop all vcpus before saving their state (Marcelo Tosatti) ...
    (Linux-Kernel)