We are using C in Linux. Is there any possibility that system() function can behave in an unexpected manner, especially when we handle signals?
We found that sometimes, the system() function blocks the execution or it throws SIGSEGV.
e.g:
system ( "/bin/mv a b" );
Are there any known flaws in using system() that would explain this?
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:So, the
system()statement blocks until the shell that runs the command completes. On Unix-like systems, the command invoked is effectively: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:
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.