Shells open redirected stdout with O_WRONLY. Such files cannot be mmaped (Write-only mapping a O_WRONLY opened file supposed to work?). Is there a work-around for this? Can I reopen the same filedescriptor (i.e., 1 == STDOUT_FILENO) but with O_RDWR without knowing a/the name of the file?
            Asked
            
        
        
            Active
            
        
            Viewed 125 times
        
    0
            
            
         
    
    
        melpomene
        
- 84,125
- 8
- 85
- 148
 
    
    
        Petr Skocik
        
- 58,047
- 6
- 95
- 142
- 
                    For mmap() to succeed, the file must be seekable. Stdin/stdout streams are not. `mmap()` will probably return (void*)-1/ENODEV – wildplasser May 18 '19 at 12:58
- 
                    @wildplasser I'm trying to `mmap` stdout redirected to a seekable file (`./a.out > some_file`). So far it looks like only Linux has a solution -- opening `/proc/self/fd/1` with `O_RDWR`. – Petr Skocik May 18 '19 at 13:00
- 
                    The file *may* be seekable, but it starts with size=zero. You may have to periodically (after write) call `mremap()` – wildplasser May 18 '19 at 13:08
- 
                    @mremap I'm doing `ftruncate` before the `mmap`. – Petr Skocik May 18 '19 at 13:19
- 
                    1@wildplasser Stdin/stdout are just as seekable as any other file handle. It all depends on what they're connected to. – melpomene May 18 '19 at 13:43