Python Data Science Jobs & Interviews
20.3K subscribers
188 photos
4 videos
25 files
326 links
Your go-to hub for Python and Data Science—featuring questions, answers, quizzes, and interview tips to sharpen your skills and boost your career in the data-driven world.

Admin: @Hussein_Sheikho
Download Telegram
⁉️ Interview question
How does Python’s mmap module behave when mapping a file that is concurrently being truncated by another process using os.ftruncate()? What are the implications for memory safety, and under what conditions might this lead to segmentation faults or undefined behavior?

When a file is mapped via `mmap` and simultaneously truncated by another process, the virtual memory pages remain valid until accessed. However, if the mapped region refers to data beyond the new file size, accessing those pages results in undefined behavior, potentially causing segmentation faults. The operating system may not immediately invalidate the mappings, leading to crashes or data corruption. This scenario highlights the need for synchronization mechanisms like file locks or signals to ensure safe concurrent access

#️⃣ tags: #Python #AdvancedPython #FileHandling #MemoryMapping #mmap #ConcurrentProgramming #OS #SystemCalls #UndefinedBehavior #SegmentationFault #FileLocking

By: t.iss.one/DataScienceQ 🚀
Please open Telegram to view this post
VIEW IN TELEGRAM