Weekend trivia: your process' memory is a file
9 hours ago
- Unix design philosophy claims 'everything is a file', but many OS functions like network connections require system calls, not file access.
- Bash special-cases paths like /dev/tcp/<server>/<port> for network connections, but this only works within bash, not for other programs.
- 'Everything is a file descriptor' is a more accurate maxim for Unix, but PIDs are separate and not directly usable as file descriptors.
- The /proc/<pid>/mem file allows reading from or writing to a process's memory via pread/pwrite with specific offsets.
- The /proc/<pid>/mem interface is simpler and more elegant than ptrace for memory debugging and modification.
- The author created memfetch to dump process memory via /proc/<pid>/mem, updated for modern 64-bit systems, though earlier mmap support was removed due to instability.
- Plan 9 from Bell Labs fully implements 'everything is a file' for network connections.