Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fork() call in c

Tags:

c

fork

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?

like image 535
deep19 Avatar asked Dec 28 '25 02:12

deep19


1 Answers

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).
like image 145
paxdiablo Avatar answered Dec 30 '25 15:12

paxdiablo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!