On an embedded platform (with no swap partition), I have an application whose main process occupies most of the available physical memory. The problem is that I want to launch an external shell script from my application, but using fork() requires that there be enough memory for 2x my original process before the child process (which will ultimately execl itself to something much smaller) can be created.
So is there any way to invoke a shell script from a C program without incurring the memory overhead of a fork()?
I’ve considered workarounds such as having a secondary smaller process which is responsible for creating shells, or having a “watcher” script which I signal by touching a file or somesuch, but I’d much rather have something simpler.
Some UNIX implementations will give you a
vfork(part of the Single UNIX spec) which is exactly likeforkexcept that it shares all the stuff with the parent.With
vfork, there are a very limited number of things you can do in the child before callingexecto overwrite the address space with another process – that’s basically whatvforkwas built for, a minimal copy version offorkfor thefork/execsequence.