Leonid Khait(deleted)
|
system() Surprise of expectation
|
Leonid Khait(deleted)
08/14/2017 1:34 AM
post117959
|
system() Surprise of expectation
There is a simple code:
#include <stdio.h>
#include <stdlib.h>
Int main (int argc, char * argv [])
{
Int ret;
...
ret = system ("uname -a"); // any sh command
...
}
system () function is executed without an error,
The output of the command "uname -a" is correct, and ret = 0;
Now twu controllers A1 and A2 in the Qnet network, and on the remote controller A2
there is a file / net / A2 / tmp / tmpfile.
#include <stdio.h>
#include <stdlib.h>
Int main (int argc, char * argv [])
{
Int ret, fp;
...
fp = open ("/ net / A2 / tmp / tmpfile", O_RDWR);
ret = system ("uname -a");
...
}
When the program is executed on the A1 controller and when the remote file is successfully opened,
So that fp> 0, the system ("uname -a") function fails with an error, "sh: can not fork, try again" is output.
The error code is ret = 256, "Socket is already connected".
How can I explain the failure of system () to call sh and execute the command when the file on the remote controller is
open?
Thank you.
|
|
|