Thinking about the process starting methodics, I was wondering why unix uses fork / exec to start a new process, and if fork / forkexec wouldn't be just as useful? I cannot see any reason for a blank exec without fork before it (unless you want to make a "trainer"-something...)
Can anybody explain to me why exec in itself would be a good thing?
What's the advantage of fork + exec versus combined?
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:What's the advantage of fork + exec versus combined?
it is used by some small program that just prepare a few file descriptors and environment variable for the "main" program before they launch it. If you had to fork() that one, it would have an useless extra cost (as you'll exit() the launcher just after fork_n_exec() ...)
This is used in some 'weird' networking programs like TCPserver, inetd and possibly some of qmail parts (though i'm no longer very sure of the last one)
This is used in some 'weird' networking programs like TCPserver, inetd and possibly some of qmail parts (though i'm no longer very sure of the last one)
Re:What's the advantage of fork + exec versus combined?
if you left it out completely, and would add a new function called exec in the libc
would that make a real difference for those programs?
Is posix (1003.1) compliance possible with this exec function, provided you don't switch pid (using some weird function)?
Code: Select all
void execchar *what) {
fork_and_exec(what);
exit(0);
}
Is posix (1003.1) compliance possible with this exec function, provided you don't switch pid (using some weird function)?
Re:What's the advantage of fork + exec versus combined?
There is also the fact that just using exec() reuses the PID of the process.. which POSIX requires AFAIK, and is sometimes useful as it allows for using wrappers and still being able to tell if the task is still alive.
I think it also preserves some other things like parent and such.
I think it also preserves some other things like parent and such.
Re:What's the advantage of fork + exec versus combined?
QNX for example support both exec() and fork() as required by POSIX and a function combining the two. Unfortunately I can't remember what it's called by probably something along the lines of run() or so.
The interesting part is actually asking whether you're interested in supporting POSIX at all.
The interesting part is actually asking whether you're interested in supporting POSIX at all.