c - munmap anonymous shared memory in forked child -


i'd know if necessary (or advisable) unmap shared memory (using munmap) in child created via fork, if memory obtained in parent, before fork, using mmap(..., map_anonymous | map_shared,...) , unmapped in parent, wait child. know whether necessary (or advisable) close file in child, if file opened in parent (before fork, using fopen) , closed in parent after child terminates.

i thinking of using user-defined signal , signal handler in parent wait child processes, , process -- wheter parent or not -- close file , unmap memory. signal sent processes in group process, in error occurred (i not want pass return values).

actually bit more complex, want know whether need this:

void sig_handler() {     if (getpid() == getpgrp()) // parent         while (proc_count--)             wait(null); // signal has been sent child processes     // every single process this:     fclose(memory->file);     munmap(memory, size);     exit(123); } 

or completely ok this:

void sig_handler() {     if (getpid() == getpgrp()) {         while (proc_count--)             wait(null);         fclose(memory->file);         munmap(memory, size);     }     exit(123); } 

i have tried closing file in 1 child process; seemed have no effect in other processes -- assume fd table copied on fork. there way make shared between processes? (probably not, suspect)

any answer appreciated. thank you.

ps. there reason why can't start question greeting (eg. hello) ?

if you're going exit process, there's no point in calling munmap(). memory unmapped process when process exits.

fclose() flush buffers holding unwritten data file. in processes - parent , child. whether or not want you.

exit() implicitly flushes buffers. _exit() not flush buffers or call other exit handlers.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -