0

In the concept of operating system we always say that in the fork() execution the child and parent have their own copy of heap and stack but they share memory segment.My question is when we say shared memory segment does that mean the text or code that they are going to execute?

2 Answers 2

1

Right (at least that happens on Linux). According to Linux manpage for fork (you can watch it by typing man 2 fork in your console or entering here if you don't have any Linux):

fork() creates a new process by duplicating the calling process. The new process, referred to as the child, is an exact duplicate of the calling process, referred to as the parent, except for the following points:

  • Process ID is unique for parent & child
  • Parent Process ID of child is the same as the parent's Parent Process ID
  • Memory locks, semaphores, signals, etc. aren't inherited
  • ...
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks so by shared memory segment it means just the text or the code ?
Shared Memory segments are segments used for sharing data between process, not executable code. Code is only shared (in memory) by forking or using lightweight process (a.k.a. threads). Wikipedia can give you a best answer that I can do.
1

In addition to the answer provided above.

The fork() system call creates a process that becomes an replica of the parent process that it is forking. Same executable.

The example provided here clearly explains the concept.here

However we may want to execute the new process with different existence .For that we require the exec() system call.

Exec() system call creates a new process from existing executable . So the problem of the new process having duplicate executable can be solved using exec().

Various types of Exec() calls are explained here.Exec()

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.