exec() and system() system calls
system() is equivalent to fork() + exec() + wait(); this means when a process run system() function it creates a new process and waits the end of this process. The new process executes the command in it's own environment, when it has finished the caller receives the signal child.
For further information man exec
man system
"exec replaces the current process image with a new process image", this means when it exits the caller exits too as the caller has become the new process.
Related videos on Youtube
Admin
Updated on September 18, 2022Comments
-
Admin over 1 year
I do understand that while exec() does not return after it executes in Unix ,system() may or may not return depending on the situation.But can anyone explain why exec() system call does not return and also the differences between exec() and system() in Unix operating system
-
Admin over 11 yearsNote that
system(3)
is not a system call, it's a library function that itself makes a few system calls. -
Admin over 11 years
system()
always returns.
-
-
psusi over 11 yearsThere's a bit more to it than that.
system()
actuallyexec()
s your default shell, and passes the string to it to process, so you can for instance, use a pipeline and other shell features. -
Charles Duffy over 2 years@psusi, not the user's default shell; it always executes
/bin/sh
-
Charles Duffy over 2 yearsThat's what
exec()
does, notsystem()
.