dslreports logo
site
 
    All Forums Hot Topics Gallery
spc

spacer




how-to block ads


Search Topic:
uniqs
972
share rss forum feed


shwetank

@airtelbroadband.in

Vfork system call

In vfork system call, parent and child processes share the pages, any change in a global variable(let say) by the child process, will reflect to the parent process as well, once it returned. Now, if we execute the exec() system call from the child process, it will load the specified program into the address space of child process, when the parent process will become active again, wouldn't it finds out the corrupted data and stack frames(with the new binary loaded by child process) ?.
Please reply,


pablo
MVM
join:2003-06-23
kudos:1

Hi,

Prior to the exec() call, you call fork(). fork() duplicates the caller. For more information, `man fork'

Cheers,
-pablo
--
openSUSE 11.1/KDE
ISP: TekSavvy DSL; backhauled via a 6KM wireless link


mich

join:2008-08-30
reply to shwetank

No, exec doesn't work like that, it detaches old address space from the calling process (and destroys it if needed) and then builds a new one from scratch.


dave
Premium,MVM
join:2000-05-04
not in ohio
kudos:8
Reviews:
·Verizon FiOS

1 recommendation

reply to pablo

said by pablo:

Prior to the exec() call, you call fork(). fork() duplicates the caller. For more information, `man fork'

He's talking about vfork, not fork. vfork was an 'efficiency' hack avoiding the need to invent copy-on-write. Right-thinking programmers consider it to be obsolete.

pablo
MVM
join:2003-06-23
kudos:1
reply to mich

said by mich:

No, exec doesn't work like that, it detaches old address space from the calling process (and destroys it if needed) and then builds a new one from scratch.

Hi,

`exec' doesn't detach itself, it replaces the existing process image:

EXEC(3) Linux Programmer's Manual EXEC(3)

NAME
execl, execlp, execle, execv, execvp - execute a file

SYNOPSIS
...

DESCRIPTION
The exec() family of functions replaces the current process image with
a new process image.
--
openSUSE 11.1/KDE
ISP: TekSavvy DSL; backhauled via a 6KM wireless link


nwrickert
sand groper
Premium,MVM
join:2004-09-04
Geneva, IL
kudos:7
Reviews:
·AT&T U-Verse
reply to shwetank

Any corruption caused before the exec() will be seen by the parent process. However, the exec() will build an entirely new address space and won't touch the existing address space. So the exec() won't cause any corruption in the parent's address space.
--
AT&T Uverse; Zyxel NBG334W router (behind the 2wire gateway); openSuSE 11.3; firefox 3.6.13


dave
Premium,MVM
join:2000-05-04
not in ohio
kudos:8
reply to pablo

Regardless of whether you want to use the word detach, exec and vfork are initimate buddies. exec does not modify the borrowed address space, but creates a new one.


pablo
MVM
join:2003-06-23
kudos:1

Hi dave See Profile,

I'm not being pedantic. As I said (and the `man' page states), `exec' does /not/ create a new environment, it overlays/replaces the existing image.

For example, given PID 1000, if I were to `exec()' wiithin, I'd still be PID 1000. Not PID 1001. OTOH, when I (v)fork(), I have PID 1000 and PID 1001. The child is PID 1001 and invokes `exec()' to overlay the existing process image with the new process.

HTH.

Cheers,
-pablo
--
openSUSE 11.1/KDE
ISP: TekSavvy DSL; backhauled via a 6KM wireless link


dave
Premium,MVM
join:2000-05-04
not in ohio
kudos:8
Reviews:
·Verizon FiOS

The way in which vfork does work is this:

If pid 1000 issues a vfork(), then pid 1000 is suspended. The child (pid 1001) gets to run using the address space of the parent. When the child executes an exec(), it gets a brand-new address space, and then the parent (pid 1000) can get unsuspended and regains use of its own address space.

Here's another way to look at it: if vfork/exec resulted in a replacement of the parent address space, then it would be no use at all and no-one would have implemented it.

It doesn't matter what the man pages say.


mich

join:2008-08-30

1 recommendation

reply to pablo

Please define what you mean by "environment", "image", "to create an environment" and "to overlay an image".

I'm not quite sure if you understand us and certainly *I* don't understand you.

"Process" and "address space" are two distinct objects. You can have many processes sharing the same address space (which is the case after vfork) and you can replace the address space of some process without destroying this process and creating a new one (what happens during exec).


pablo
MVM
join:2003-06-23
kudos:1

said by mich:

I'm not quite sure if you understand us and certainly *I* don't understand you.

Pardon? Incredible.

-pablo
--
openSUSE 11.1/KDE
ISP: TekSavvy DSL; backhauled via a 6KM wireless link