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

2 views (last 30 days)
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

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 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)

More Answers (0)

Categories

Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!