Re: What is the practical significance of fork

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I believe his question actually sounds like: why does Linux need two system calls to start running a new program? Wouldn't it be simpler to do this the way Win32 does it: a CreateProcess() system call that actually loads a NEW program in  NEW process?

Enrico Granata
Computer Science & Engineering Department (EBU3B) - Room 3240
office phone 858 534 9914
University of California, San Diego

On Dec 15, 2010, at 10:34 AM, Mulyadi Santosa wrote:

Hi :)

On Thu, Dec 16, 2010 at 01:01, Chaitannya Mahatme <chaitannya@xxxxxxxxx> wrote:
I tried finding answer to this question in many books but never quite got a
satisfactory answer to this question.

Satisfaction is hard to reach sometimes, you know :)

A fork process would replicate it parent, my question is

Why is fork necessary to create a process.

it's just a name actually.... what really matters is the procedure
which are done inside fork() (as system call).

Why replicate a existing process
before creating a new process.

Replicate? You mean Copy on Write(COW)?

OK, I think what you refer here is actually COW. Essentially, when new
process is created (forked), mainly new task struct, new signal
handler tables, vma tables are created. But specificly for the VMAs
(Virtual Memory area), they are simply pointing to its parent.

only when a write process is targetting that COW-ed area, page fault
is invoked and new page...one by one..as needed..are allocated

The exec algorithm is executed after fork which overrides what fork has
done, then why do fork. Why can't we directly do exec.

I am not sure that I understand the above question correctly, you mean
"why fork then exec if we could simply do exec?"

First of all, I forgot few details about fork etc...but let's assume
there is indeed exec after fork. What you need to know here is that
fork() is a way to prepare complete process structure along with the
process address space.

While exec spesifically just deal with how the file (quite likely ELF
binary) should be loaded and executed. So, in short, fork() build
foundation, exec() put the bricks and mortars.

After all, again, fork() just COW-ed its parent VMAs...thus when exec
goes, there is no significant penalty.... no page is allocated for VMA
after all during fork()

--
regards,

Mulyadi Santosa
Freelance Linux trainer and consultant

blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux