开发者

fork() call in c

I have used fork() to create 2 different processes operating开发者_开发百科 on 2 different address spaces. Now, in parent process I need the value of a variable from child's address space or if the child process can modify the variable in parent's address space. Is this possible?


No, once you've forked, each process gets its own address space and you'll have to look into either:

  • some form of IPC between the processes to access each others data (such as shared memory or message queues).
  • some more lighweight variant of fork that allows sharing of data (including possibly threading).


Once you have two processes, sharing data needs interprocess communication: file, pipe or shared memory.


If you mean exchanging data between these two processes you can not. You can do it by system APIs like SharedMemory, Message Passing, Pipeline, Socket, ...


As you have created two process using fork command Both Process will be in different address space so they will only communicate by IPC, message passing ,Piping , Shared Memory etc. otherwise one process can't access other process data as thay do have Process specific data and similarly threads also have thread specific data

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜