PHP fork process - getting child output in parent

前端 未结 3 2005
忘掉有多难
忘掉有多难 2021-01-20 03:44

I want to achieve the following:

Initialize an array. Child process adds some elements to the array. Parent process adds some elements to the array. Finally before

3条回答
  •  轮回少年
    2021-01-20 04:20

    The child's code is missing the print_r() statement.

    The parent won't print what the child added to values, as the addition was done after the child process had been fork()ed off, and with this it had gotten its own copy of the prcoess' memory.

    From the fork-tag's excerpt (emphasis by me):

    The fork() function is the Unix/Linux/POSIX way of creating a new process by duplicating the calling process.

    This behaviour of forking is different from threading where all threads share the same address space.

提交回复
热议问题