Memory mapped file descriptor opened after execl is empty but should have content
I am working on sharing memory to a execl'd process using mmap MAP_SHARED memory. I open a file before execl, mmap the returned fd, write to the region, leave the fd open and pass the opened fd to the execl'd process. I believe I have a lapse in my understanding how MMAP works under-the-hood and as a result I'm not seeing the content in my execl'd process.
Here is the basic logic/order of my code:
addr = mmap(NULL, sb.size, PROTO_READ|PROTO_WRITE, MAP_SHARED, fd, 0);
memcpy(addr, stuff, size(stuff));
//addr now has content
execl("./test", "test", fd_str, NULL);
new_addr=mmap(NULL, sb.size, PROTO_READ|PROTO_WRITE, MAP_SHARED, atoi(fd_str), 0);
//new_addr is all empty.
Let me know if this is the right forum for this question. Thanks for your help.
just an FYI, from the man pages for execve, file descriptors are left open on execve unless FD_CLOEXEC is set.