Passing a pointer to process spawned with exec()

后端 未结 6 1291
花落未央
花落未央 2021-01-23 14:44

I would like to pass a pointer (I am putting a file with data in memory with mmap) to processes spawned using fork + exec, but I am stuck on how to pass a pointer to the exec()

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-23 14:58

    Consider passing the offset to the memory within the file to the child process. If the offset is zero, then don't bother, but if you need to pass a 'pointer' to part way through the file, then convert that to an offset from the start address, and pass that to the child. The child can then get to the data by adding the offset to the address it obtains for the mapped file.

提交回复
热议问题