shmat(3) function returns 0xffffffffffffffff address
Solution 1:
From man:
shmat() returns the address at which the shared memory segment has been mapped into the calling process' address space when successful, shmdt() returns 0 on successful completion. Otherwise, a value of -1 is returned, and the global variable errno is set to indicate the error.
The 0xffffffffffffffff
pointer you see, is -1
signifying error.
Add to your program an if which checks return values of shmat
and shmget
for errors. Inside the if you can use the perror
function to print an error message that will tell you what went wrong.
This is a general rule. You should always check return values of system calls:
a = system_call_x();
if (a == (void*) -1) {
perror("system_call_x failed, exiting");
exit(1);
}