I would like to know the difference between exec and fork commands?
Fork and Exec commands
Started by BigLinux, Jul 26 2009 07:54 AM
4 replies to this topic
#1
Posted 26 July 2009 - 07:54 AM
|
|
|
#2
Posted 31 July 2009 - 01:12 AM
Fork() creates a child process (or in a shell creates a subshell from which to execute the code), whereas exec() replaces the currently running process (or shell) with the executable file given to exec, unless of course there's an error.
Essentially, fork = create new; exec = replace with.
- Zeke
Essentially, fork = create new; exec = replace with.
- Zeke
#3
Posted 31 July 2009 - 04:37 AM
Note that (depending on the OS) fork() may replicate some stuff, like the IP, handle tables, ect... for the new process.
#4
Posted 31 July 2009 - 05:53 AM
isn't it like that your program waits for exec to have ran finished, while fork starts the other process and keeps the current program running, doing whatever it should?
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
I study Information Systems at Karlstad University when I'm not on CodeCall
#5
Posted 31 July 2009 - 06:50 AM
Actually don't think so. exec(), according to the always trustable Wikipedia, does not normally return to the calling process, and fork() starts an independent process. exec() can also return a status number to the calling process, whereas fork() cannot (at least I think not). Just technically in multithreaded environments it's all processes given unique PID's. exec() uses the same PID as it's calling process, fork() is given a unique PID, which is also returned to the parent process so that it can continue to refer to the child process through signals.
Edited by ZekeDragon, 31 July 2009 - 06:53 AM.
Learning something every day...


Sign In
Create Account


Back to top









