shmget ???

shmget ???

Post by Andrew L. Sandov » Thu, 09 Feb 1995 04:58:05



Can anyone tell me why the following code always tells me that the
Shared Memory ID is ZERO, but, the ipcs command shows the real shmid?

I am running similar code on HPUX, but, the id is sent to syslog, rather
than stdout, which gives me the correct ID.

Any Ideas or comments are appreciated.  Thanks in advance.

shmzero.c:
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/fcntl.h>

main()
{
 int shmid;
 long *shared_at;

 if(shmid = shmget(IPC_PRIVATE,10,0600)==-1) { perror("shmget failed");
                                          exit(1); }

 fprintf(stdout,"Shared Mem ID = %d\n",shmid);
 fprintf(stdout,"Zeroing Counter.\n");
 shared_at =(long*)shmat(shmid,0,O_RDWR);
 if(shared_at<0) { perror("shmat failed"); exit(1); }
 shared_at[0]=0;
 shmdt((void*)shared_at);
 exit(0);

Quote:}

 
 
 

shmget ???

Post by Bruno Haib » Fri, 10 Feb 1995 23:56:00



Quote:>Can anyone tell me why the following code always tells me that the
>Shared Memory ID is ZERO, but, the ipcs command shows the real shmid?

gcc already tells you:

$ gcc -Wall -O shmzero.c
shmzero.c:9: warning: return-type defaults to `int'
shmzero.c: In function `main':
shmzero.c:13: warning: suggest parentheses around assignment used as truth value

Quote:> if(shmid = shmget(IPC_PRIVATE,10,0600)==-1) { perror("shmget failed");

Put in parentheses, and it will work like a charm.

                    Bruno Haible


 
 
 

1. xanim causes shmget error

I installed XF86.3.1.1 for a while and had no problems. Yesterday I
installed xanim (2.69.7.6). When loading a animation file, xanim
causes the following error:

shmget, function not implemented.

What is shmget and what could be the cause of this error. The
animationfile
.mov is correct and played it on a SUN and it worked OK.

Thanx.
Chris van Mierlo

2. regular user's command being owned by root

3. HELP: shmget() and shmat()

4. help with Bernoulli SCSi Drive

5. Gdk-WARNING **: shmget failed!

6. Windows to unix installation (files change to garble)

7. Shmget failed!

8. /dev/ttyp?

9. Maximum possible size of shmget() segments?

10. shmget() system call

11. shmget

12. cdrecord: Invalid argument. shmget failed

13. Fork, shmget, etc.