tags:

views:

112

answers:

2

I've been reading its man page but haven't yet been successful in figuring out how it works. On calling system(), is a new child process forked and the shell binary exec()-ed in it? That may be a stupid guess though.

A: 

Yes, system("foo bar") is equivalent to execv("/bin/sh", ["sh", "-c", "foo bar"]).

daf
Posix requires that system() ignore SIGINT and SIGQUIT and block SIGCHLD.
Bastien Léonard
Yes. The example implementation Lance pointed to does that.
+4  A: 

Yes, system() is essentially a fork() and exec() "sh -c" for the passed command string. An example implementation (from eglibc, recently forked from glibc) can be found here.

Lance Richardson
Thanks,that link was really helpful :)