MOHAMED
MOHAMED

Reputation: 43558

malloc in fork child

I m developing an application in which I launch a fork to execute a child process.

In the child process I want to create a linked list with many nodes and each node should created with malloc() and then copy the linked list to the parent. because the linked list is created only in the child and it does not exist in the parent.

How to do it ?

Upvotes: 0

Views: 541

Answers (3)

AlgebraWinter
AlgebraWinter

Reputation: 321

Ed is right, shared memory is the answer. On non-Windows just do man shmget or here's a good reference: http://www.cs.cf.ac.uk/Dave/C/node27.html

Upvotes: 1

Ed Heal
Ed Heal

Reputation: 60017

Shared memory is the ticket. See this page

Upvotes: 1

unwind
unwind

Reputation: 400029

You must use some inter-process communications method, like shared memory, pipes, files on disk, sockets, and so on. Since processes are typically isolated from each other, you can't just pass the pointers around.

Upvotes: 2

Related Questions