Why if a declare a shared memory in main.c when I do fork() and execve the child (child.c), the child don't see the shared memory?
The variables are declared in header.h but if I declare them in main.c it does not work anyway
fork() generates a new process as the child-process of the original one. For the virtual memory space, Linux handles it by COW technology. This optimization roots on the fact that, if exec*() another program is called in the child-process imediately after fork(), eager copy the virtual space is useless.
In your case, you fock() from gestore and then execl() the program figlioA, which matches the design of fork-COW. Hence, in the child-process, the whole virtual space of its father-process is dropped and thus invisible.
If you put everything in the same source file, and keep running the same program in the child-process, the virtual space inherited from its father-process will then COW-ed, and hence elements are still valid and visible. However, for this situation, your shared_data is shared between the two process only for the name —- modifying it in one process triggers Linux to copy it in physical memory and to reattach the map between physical memory frame and virtual memory page, and thus the modification is invisible in another process.