I am getting a -1 return value, even after running a command successfully via system() call. Please see the following C code for more information.
system("ping -w 3 -c 1 -q -I 63.254.203.24 63.254.203.26 >/dev/null");
and then I am checking the return value of this system() call, even though it is pingable but I found -1 as a return value.
Fortunately, I got the answer. it was fork failed due to memory failure. It is not a good idea to use system() call.
Thanks for the support and answer.
to see the actual return value use
WEXITSTATUS(n)
and the reason whysystem
doesn't return the actual value is because (and this is only valid for linux) it is implemented usingfork
,exec
andwait
the later returns the status of the process which contains whether the process ended normally or because of a signal plus the actual return value , and to access those different values you'll have to use macro's such asWEXITSTATUS(n)
these macros are mentioned inman 3 wait
The section RETURN VALUE of
man system
: