mmap: effect of other processes writing to a file previously mapped read-onlyHow does copy-on-write in fork() handle multiple fork?Writing own daemon. systemd error: Failed to read PID from file: Invalid argumentPagemap on memory mapped devices not workingWhen writing a file, permissions are write onlyUnderstanding MMAPMonitoring page cache / memory mapped files accessmajor page faults on anon mappingsHow to use dd if=/dev/mem in place of devmem ?Is there a standard for the Linux user-space memory map?

How do I write real-world stories separate from my country of origin?

How could the B-29 bomber back up under its own power?

Anatomically correct Guivre

Caught with my phone during an exam

size of pointers and architecture

Is the default 512 byte physical sector size appropriate for SSD disks under Linux?

amsmath: How can I use the equation numbering and label manually and anywhere?

Wifi light switch needs neutral wire. Why? AND Can that wire be a skinny one?

Is ideal gas incompressible?

Is there a word for pant sleeves?

Singular Integration

How can I reduce the size of matrix?

JavaScript: Access 'this' when calling function stored in variable

What happens when redirecting with 3>&1 1>/dev/null?

Is a world with one country feeding everyone possible?

Does attacking (or having a rider attack) cancel Charge/Pounce-like abilities?

Why is a weak base more able to deprotonate a strong acid than a weak acid?

Are there any tips to help hummingbirds find a new feeder?

Why is unzipped file smaller than zipped file

Are there historical examples of audiences drawn to a work that was "so bad it's good"?

Surface of the 3x3x3 cube as a graph

How many wires should be in a new thermostat cable?

csname in newenviroment

Is it normal to "extract a paper" from a master thesis?



mmap: effect of other processes writing to a file previously mapped read-only


How does copy-on-write in fork() handle multiple fork?Writing own daemon. systemd error: Failed to read PID from file: Invalid argumentPagemap on memory mapped devices not workingWhen writing a file, permissions are write onlyUnderstanding MMAPMonitoring page cache / memory mapped files accessmajor page faults on anon mappingsHow to use dd if=/dev/mem in place of devmem ?Is there a standard for the Linux user-space memory map?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I am trying to understand what happens when a file, which has been mapped into memory by the mmap system call, is subsequently written to by other processes.



I have mmaped memory with PROT_READ protection in "process A". If I close the underlying file descriptor in process A, and another process later writes to that file (not using mmap; just a simple redirection of stdout to the file using > in the shell), is the mmaped memory in the address space of process A affected? Given that the pages are read-only, I would expect them not to change. However, process A is being terminated by SIGBUS signals as a result of invalid memory accesses (Non-existent physical address at address 0x[...]) when trying to parse the mapped memory. I am suspecting that this is stemming from writes to the backing file by other processes. Would setting MAP_PRIVATE be sufficient to completely protect this memory from other processes?










share|improve this question




























    2















    I am trying to understand what happens when a file, which has been mapped into memory by the mmap system call, is subsequently written to by other processes.



    I have mmaped memory with PROT_READ protection in "process A". If I close the underlying file descriptor in process A, and another process later writes to that file (not using mmap; just a simple redirection of stdout to the file using > in the shell), is the mmaped memory in the address space of process A affected? Given that the pages are read-only, I would expect them not to change. However, process A is being terminated by SIGBUS signals as a result of invalid memory accesses (Non-existent physical address at address 0x[...]) when trying to parse the mapped memory. I am suspecting that this is stemming from writes to the backing file by other processes. Would setting MAP_PRIVATE be sufficient to completely protect this memory from other processes?










    share|improve this question
























      2












      2








      2


      1






      I am trying to understand what happens when a file, which has been mapped into memory by the mmap system call, is subsequently written to by other processes.



      I have mmaped memory with PROT_READ protection in "process A". If I close the underlying file descriptor in process A, and another process later writes to that file (not using mmap; just a simple redirection of stdout to the file using > in the shell), is the mmaped memory in the address space of process A affected? Given that the pages are read-only, I would expect them not to change. However, process A is being terminated by SIGBUS signals as a result of invalid memory accesses (Non-existent physical address at address 0x[...]) when trying to parse the mapped memory. I am suspecting that this is stemming from writes to the backing file by other processes. Would setting MAP_PRIVATE be sufficient to completely protect this memory from other processes?










      share|improve this question














      I am trying to understand what happens when a file, which has been mapped into memory by the mmap system call, is subsequently written to by other processes.



      I have mmaped memory with PROT_READ protection in "process A". If I close the underlying file descriptor in process A, and another process later writes to that file (not using mmap; just a simple redirection of stdout to the file using > in the shell), is the mmaped memory in the address space of process A affected? Given that the pages are read-only, I would expect them not to change. However, process A is being terminated by SIGBUS signals as a result of invalid memory accesses (Non-existent physical address at address 0x[...]) when trying to parse the mapped memory. I am suspecting that this is stemming from writes to the backing file by other processes. Would setting MAP_PRIVATE be sufficient to completely protect this memory from other processes?







      c mmap






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 3 hours ago









      user001user001

      1,63732141




      1,63732141




















          1 Answer
          1






          active

          oldest

          votes


















          3















          If I close the underlying file descriptor in process A,




          closing the file descriptor doesn't change anything at all




          another process later writes to that file (not using mmap; just a simple redirection of stdout to the file using > in the shell), is the mmaped memory in the address space of process A affected?




          It may be. The manpage of mmap(2) says:



           MAP_PRIVATE
          ...
          It is unspecified whether changes made to the file
          after the mmap() call are visible in the mapped region.


          In practice, changes made by other processes seem to be reflected in the content of the mmaped region, at least for regular files.




          However, process A is being terminated by SIGBUS signals as a result of invalid memory accesses (Non-existent physical address at address 0x[...]) when trying to parse the mapped memory.




          I'm expecting that to happen when you truncate a mmaped file.




          Would setting MAP_PRIVATE be sufficient to completely protect this memory from other processes?




          No, MAP_PRIVATE only prevent modifications to the memory from being carried through to the backing file, not the reverse.






          share|improve this answer























          • Thanks, that helps. So it sounds like mmap is not the right tool for reading (and preserving in memory) the current state of a file, when that file might be modified by other processes before the memory has been completely read by the process which created the map?

            – user001
            2 hours ago







          • 1





            hurd seems to have a MAP_COPY for that, but that's not supported on Linux/BSD/Solaris/etc. You can read more about it here.

            – mosvy
            1 hour ago











          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f519850%2fmmap-effect-of-other-processes-writing-to-a-file-previously-mapped-read-only%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3















          If I close the underlying file descriptor in process A,




          closing the file descriptor doesn't change anything at all




          another process later writes to that file (not using mmap; just a simple redirection of stdout to the file using > in the shell), is the mmaped memory in the address space of process A affected?




          It may be. The manpage of mmap(2) says:



           MAP_PRIVATE
          ...
          It is unspecified whether changes made to the file
          after the mmap() call are visible in the mapped region.


          In practice, changes made by other processes seem to be reflected in the content of the mmaped region, at least for regular files.




          However, process A is being terminated by SIGBUS signals as a result of invalid memory accesses (Non-existent physical address at address 0x[...]) when trying to parse the mapped memory.




          I'm expecting that to happen when you truncate a mmaped file.




          Would setting MAP_PRIVATE be sufficient to completely protect this memory from other processes?




          No, MAP_PRIVATE only prevent modifications to the memory from being carried through to the backing file, not the reverse.






          share|improve this answer























          • Thanks, that helps. So it sounds like mmap is not the right tool for reading (and preserving in memory) the current state of a file, when that file might be modified by other processes before the memory has been completely read by the process which created the map?

            – user001
            2 hours ago







          • 1





            hurd seems to have a MAP_COPY for that, but that's not supported on Linux/BSD/Solaris/etc. You can read more about it here.

            – mosvy
            1 hour ago















          3















          If I close the underlying file descriptor in process A,




          closing the file descriptor doesn't change anything at all




          another process later writes to that file (not using mmap; just a simple redirection of stdout to the file using > in the shell), is the mmaped memory in the address space of process A affected?




          It may be. The manpage of mmap(2) says:



           MAP_PRIVATE
          ...
          It is unspecified whether changes made to the file
          after the mmap() call are visible in the mapped region.


          In practice, changes made by other processes seem to be reflected in the content of the mmaped region, at least for regular files.




          However, process A is being terminated by SIGBUS signals as a result of invalid memory accesses (Non-existent physical address at address 0x[...]) when trying to parse the mapped memory.




          I'm expecting that to happen when you truncate a mmaped file.




          Would setting MAP_PRIVATE be sufficient to completely protect this memory from other processes?




          No, MAP_PRIVATE only prevent modifications to the memory from being carried through to the backing file, not the reverse.






          share|improve this answer























          • Thanks, that helps. So it sounds like mmap is not the right tool for reading (and preserving in memory) the current state of a file, when that file might be modified by other processes before the memory has been completely read by the process which created the map?

            – user001
            2 hours ago







          • 1





            hurd seems to have a MAP_COPY for that, but that's not supported on Linux/BSD/Solaris/etc. You can read more about it here.

            – mosvy
            1 hour ago













          3












          3








          3








          If I close the underlying file descriptor in process A,




          closing the file descriptor doesn't change anything at all




          another process later writes to that file (not using mmap; just a simple redirection of stdout to the file using > in the shell), is the mmaped memory in the address space of process A affected?




          It may be. The manpage of mmap(2) says:



           MAP_PRIVATE
          ...
          It is unspecified whether changes made to the file
          after the mmap() call are visible in the mapped region.


          In practice, changes made by other processes seem to be reflected in the content of the mmaped region, at least for regular files.




          However, process A is being terminated by SIGBUS signals as a result of invalid memory accesses (Non-existent physical address at address 0x[...]) when trying to parse the mapped memory.




          I'm expecting that to happen when you truncate a mmaped file.




          Would setting MAP_PRIVATE be sufficient to completely protect this memory from other processes?




          No, MAP_PRIVATE only prevent modifications to the memory from being carried through to the backing file, not the reverse.






          share|improve this answer














          If I close the underlying file descriptor in process A,




          closing the file descriptor doesn't change anything at all




          another process later writes to that file (not using mmap; just a simple redirection of stdout to the file using > in the shell), is the mmaped memory in the address space of process A affected?




          It may be. The manpage of mmap(2) says:



           MAP_PRIVATE
          ...
          It is unspecified whether changes made to the file
          after the mmap() call are visible in the mapped region.


          In practice, changes made by other processes seem to be reflected in the content of the mmaped region, at least for regular files.




          However, process A is being terminated by SIGBUS signals as a result of invalid memory accesses (Non-existent physical address at address 0x[...]) when trying to parse the mapped memory.




          I'm expecting that to happen when you truncate a mmaped file.




          Would setting MAP_PRIVATE be sufficient to completely protect this memory from other processes?




          No, MAP_PRIVATE only prevent modifications to the memory from being carried through to the backing file, not the reverse.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 2 hours ago









          mosvymosvy

          11.6k11340




          11.6k11340












          • Thanks, that helps. So it sounds like mmap is not the right tool for reading (and preserving in memory) the current state of a file, when that file might be modified by other processes before the memory has been completely read by the process which created the map?

            – user001
            2 hours ago







          • 1





            hurd seems to have a MAP_COPY for that, but that's not supported on Linux/BSD/Solaris/etc. You can read more about it here.

            – mosvy
            1 hour ago

















          • Thanks, that helps. So it sounds like mmap is not the right tool for reading (and preserving in memory) the current state of a file, when that file might be modified by other processes before the memory has been completely read by the process which created the map?

            – user001
            2 hours ago







          • 1





            hurd seems to have a MAP_COPY for that, but that's not supported on Linux/BSD/Solaris/etc. You can read more about it here.

            – mosvy
            1 hour ago
















          Thanks, that helps. So it sounds like mmap is not the right tool for reading (and preserving in memory) the current state of a file, when that file might be modified by other processes before the memory has been completely read by the process which created the map?

          – user001
          2 hours ago






          Thanks, that helps. So it sounds like mmap is not the right tool for reading (and preserving in memory) the current state of a file, when that file might be modified by other processes before the memory has been completely read by the process which created the map?

          – user001
          2 hours ago





          1




          1





          hurd seems to have a MAP_COPY for that, but that's not supported on Linux/BSD/Solaris/etc. You can read more about it here.

          – mosvy
          1 hour ago





          hurd seems to have a MAP_COPY for that, but that's not supported on Linux/BSD/Solaris/etc. You can read more about it here.

          – mosvy
          1 hour ago

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f519850%2fmmap-effect-of-other-processes-writing-to-a-file-previously-mapped-read-only%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

          Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

          Ласкавець круглолистий Зміст Опис | Поширення | Галерея | Примітки | Посилання | Навігаційне меню58171138361-22960890446Bupleurum rotundifoliumEuro+Med PlantbasePlants of the World Online — Kew ScienceGermplasm Resources Information Network (GRIN)Ласкавецькн. VI : Літери Ком — Левиправивши або дописавши її