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

  • 4
    Note that system(3) is not a system call, it's a library function that itself makes a few system calls. Commented Oct 30, 2012 at 15:18
  • system() always returns.
    – psusi
    Commented Feb 18, 2013 at 15:14

2 Answers 2


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.

  • 2
    There's a bit more to it than that. system() actually exec()s your default shell, and passes the string to it to process, so you can for instance, use a pipeline and other shell features.
    – psusi
    Commented Feb 18, 2013 at 15:14
  • @psusi, not the user's default shell; it always executes /bin/sh Commented Feb 20, 2022 at 16:31

This a system call in Unix OS that replaces the currently running process with a information from the binary program.

  • That's what exec() does, not system(). Commented Feb 20, 2022 at 16:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .