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:}