The system()
function does what it is supposed to do perfectly well. The behaviour is pretty reliable as long as it is invoked correctly. It has two modes of operation:
- Check whether there is a command interpreter available - when the argument is a null pointer.
- Run the command given, waiting for the command to complete before returning.
So, the system()
statement blocks until the shell that runs the command completes. On Unix-like systems, the command invoked is effectively:
"sh", "-c", "...argument to system...", NULL
This means that the string passed is interpreted by the shell. How long that takes depends on the command that is executed. You can consider using the shell notations to run the command in background if you need to:
system("( /bin/mv a b & )");
There are few circumstances where system()
will itself generate SIGSEGV. You would have to pass it an invalid pointer, a pointer to somewhere invalid in the program.