Shared Memory With Two Processes In C?

后端 未结 4 1501
鱼传尺愫
鱼传尺愫 2021-01-03 07:42

I want to do the following:

Parent process creates a child process. Then the child process reads n int\'s from the user and store them in a shared memory. The parent

4条回答
  •  既然无缘
    2021-01-03 08:35

    Your description seems to not be correct since there is no code that outputs "Parent Wrote <>".

    You are reading numbers and storing them as int in *n++, but then you are appending a '\n' character to the n-int array and you are treating shm as a string?

    It seems to me that in your child you are creating a shared memory, writing to it and then closing (discarding) the shared memory. Then your second part opens a new shared memory with the same segment, but yet it is a new shared memory. Normally one process creates a shared memory, then the second opens it and when the last process closes the shared memory, then it is freed by the OS.

提交回复
热议问题