Why does the SYSTEM function in a MEX-file lock-up MATLAB 6.1 (R12.1) forever?

2 vues (au cours des 30 derniers jours)
Why does the SYSTEM function in a MEX-file lock-up MATLAB 6.1 (R12.1) forever?
I am using Linux 2.2.18-SMP (SuSE Linux 7.1) and when I use the function SYSTEM inside a MEX file my MATLAB locks up forever.
My file called bugs.c looks like the following:
#include "mex.h"
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray*prhs[] )
{
/* this locks matlab 6.1 up, forever... */
int rc;
rc = system ("ls");
return;
}
Under Linux 2.2.18-SMP and MATLAB 6.1 the mex file built from bug.c locks MATLAB and my 10 or so processes forever. The processes can only be removed with
kill -9

Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 27 Juin 2009
This bug has been fixed in Release 14 Service Pack 2 (R14SP2). For previous releases, please read below for any possible workarounds:
The Java Virtual Machine (JVM) has a reaper thread which is waiting for other threads to die. It's also grabbing the system() child before the wait4() call inside the MEX file can reap its own child. MATLAB runs all of our system() calls via a process that was forked early on, both for efficiency and for isolation from the JVM. In MATLAB 6.x you have two workarounds:
1) Use mexCallMATLAB("system('ls')") instead (preferred method)
2) Run MATLAB using the -nojvm option. To do this on Unix, type:
matlab -nojvm
to start MATLAB. On the PC you need to change your MATLAB shortcut so that it says:
$MATLAB\bin\win32\matlab.exe -nojvm (where $MATLAB is your root MATLAB directory)

Plus de réponses (0)

Catégories

En savoir plus sur Write C Functions Callable from MATLAB (MEX Files) dans Help Center et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by