Re: Small memory penalty on forking and command-execution?
From: Joe Pfeiffer (pfeiffer_at_cs.nmsu.edu)
Date: 04/01/05
- Next message: Tauno Voipio: "Re: Linux Kernel Socket"
- Previous message: Anders Christensen: "Re: Small memory penalty on forking and command-execution?"
- Maybe in reply to: Anders Christensen: "Re: Small memory penalty on forking and command-execution?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 31 Mar 2005 22:44:41 -0700
Anders Christensen <andersc1@hotmail.com> writes:
> I'm making a program for a device with limited memory. My program
> allocates memory using malloc() during runtime (there is enough memory
> to the intended use of the program). Now I need to execute a command from
> within my program, so I'm thinking about forking immediately followed by
> executing the command in the child-process...
That's the standard approach.
> I do not (always) have enough free memory to store an exact copy of the
> parent. I've read that fork() uses copy-on-write, but I can't figure out,
> if the exec-call will cause the parent's memory to be copied. Can someone
> help me on that?
No, it won't. At worst it would only copy those pages that the new
command needs to write over, which are pages the new command needs to
allocate anyway; this would be a time and not a space penalty. I
expect it's actually bright enough to figure out that there's no
point in making the copy at all.
> Which of fork() and vfork() will give the smallest memory penalty? And
> which exec-family function will give the smallest memory penalty?
man vfork
vfork is the winner, by a very small margin (huh. Until I checked
myself, I thought they had become synonyms).
I can't imagine that which flavor of exec() you use could make a
significant difference.
-- Joseph J. Pfeiffer, Jr., Ph.D. Phone -- (505) 646-1605 Department of Computer Science FAX -- (505) 646-1002 New Mexico State University http://www.cs.nmsu.edu/~pfeiffer
- Next message: Tauno Voipio: "Re: Linux Kernel Socket"
- Previous message: Anders Christensen: "Re: Small memory penalty on forking and command-execution?"
- Maybe in reply to: Anders Christensen: "Re: Small memory penalty on forking and command-execution?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|