Athanasios V.
Athanasios V.

Reputation: 319

parent and child process using fork

Under Linux when I call the fork() system call the parent and child processes share the same data. What kind of data does it mean? (e.g. heap data or something?)

I mean if there is a copy of all memory (stack, heap, and text) then this is inefficient. There must be something else happening.

Copy-on-write tells me that until there is a write everything is not duplicated.

Upvotes: 1

Views: 2404

Answers (1)

kaylum
kaylum

Reputation: 14046

The parent and child processes do not share any data. Not in the sense that a change by one process will be seen by the other process. At the time of the fork the child process is an exact duplicate of the parent process in terms of data (but not everything is duplicated - see the fork man page for exact details). For data all global, heap and stack are duplicated. But again, note that it is "duplicated" not "shared".

Upvotes: 2

Related Questions